From: Raymond T. <rt...@us...> - 2012-08-17 16:55:56
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Maxima, A Computer Algebra System". The branch, master has been updated via 4a7a591d0f09b0729a7d13042529ca96aed4891c (commit) from 7ee4574668317b45586adca4cb92a47f26b90988 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 4a7a591d0f09b0729a7d13042529ca96aed4891c Author: Raymond Toy <toy...@gm...> Date: Fri Aug 17 09:54:32 2012 -0700 Fix Bug 3440046: elliptic_f(0.5,1) signals error src/ellipt.lisp: o Don't call elliptic_kc unless we have to. o Signal errors if we try to compute more than one period for elliptic_f(x,1), since elliptic_f(%pi/2,1) is infinity. tests/rtest16.mac: o Add test for elliptic_f(0.5,1) o Add tests for elliptic_f(2.0,1); diff --git a/src/ellipt.lisp b/src/ellipt.lisp index dd014f9..7bd05d1 100644 --- a/src/ellipt.lisp +++ b/src/ellipt.lisp @@ -1261,8 +1261,10 @@ first kind: ;; F(z|m) = F(z - pi*round(Re(z)/pi)|m) + 2*round(Re(z)/pi)*K(m) (let ((period (round (realpart phi-arg) pi))) (add (base (- phi-arg (* pi period)) m-arg) - (mul (mul 2 period) - (elliptic-k m-arg)))))) + (if (zerop period) + 0 + (mul (mul 2 period) + (elliptic-k m-arg))))))) ;; Complete elliptic integral of the first kind (defun elliptic-k (m) @@ -1284,6 +1286,9 @@ first kind: ((= m 0) ;; A&S 17.4.19 (float (/ pi 2))) + ((= m 1) + (maxima::merror + (intl:gettext "elliptic_kc: elliptic_kc(1) is undefined."))) (t (let ((k (sqrt m))) (to (bigfloat::bf-rf 0.0 (* (- 1 k) @@ -2075,14 +2080,20 @@ first kind: ;; elliptic_f(phi,m) = sin(phi)*rf(cos(phi)^2, 1-m*sin(phi)^2,1) (defun bf-elliptic-f (phi m) (flet ((base (phi m) - (let ((s (sin phi)) - (c (cos phi))) - (* s (bf-rf (* c c) (- 1 (* m s s)) 1))))) + (cond ((= m 1) + ;; F(z|1) = log(tan(z/2+%pi/4)) + (log (tan (+ (/ phi 2) (/ (%pi phi) 4))))) + (t + (let ((s (sin phi)) + (c (cos phi))) + (* s (bf-rf (* c c) (- 1 (* m s s)) 1))))))) ;; Handle periodicity (see elliptic-f) (let* ((bfpi (%pi phi)) (period (round (realpart phi) bfpi))) (+ (base (- phi (* bfpi period)) m) - (* 2 period (bf-elliptic-k m)))))) + (if (zerop period) + 0 + (* 2 period (bf-elliptic-k m))))))) ;; elliptic_kc(k) = rf(0, 1-k^2,1) ;; @@ -2094,6 +2105,9 @@ first kind: (if (maxima::$bfloatp m) (maxima::$bfloat (maxima::div 'maxima::$%pi 2)) (float (/ pi 2) 1e0))) + ((= m 1) + (maxima::merror + (intl:gettext "elliptic_kc: elliptic_kc(1) is undefined."))) (t (bf-rf 0 (- 1 m) 1)))) diff --git a/tests/rtest16.mac b/tests/rtest16.mac index 2f5506b..9267ea6 100644 --- a/tests/rtest16.mac +++ b/tests/rtest16.mac @@ -2282,4 +2282,20 @@ polarform((a+1)/2 - a/2 - 0.5); polarform((a+1)/2 - a/2 - 0.5b0); 0.0b0$ +/* + * ID: 3440046: elliptic_f(0.5,1) signals error + * + * Add a few more tests for invalid values. + */ +closeto(elliptic_f(0.5,1)-elliptic_f(1/2,1), 1e-15); +true; + +closeto(elliptic_f(0.5b0,1) - bfloat(elliptic_f(1/2,1)), 1b-16); +true; + +errcatch(elliptic_f(2.0,1)); +[]; + +errcatch(elliptic_f(2b0,1)); +[]; ----------------------------------------------------------------------- Summary of changes: src/ellipt.lisp | 26 ++++++++++++++++++++------ tests/rtest16.mac | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) hooks/post-receive -- Maxima, A Computer Algebra System |