asin and acos wrong



Last fall, a few of us talked about  replacing the floating point code in 
trigi.lisp 
with Common Lisp functions.  I think we agreed that it would be a good 
thing to
do. I did a few experiments and then forgot about it. We may have even 
talked 
about possibly replacing $%i with $c(0 1) everywhere in Maxima -- this 
would 
allow floating point evaluation without going through $rectform.

My experimental code follows  --  it needs testing.  I see that I played 
with
adding error checking to just the asec function.  A big chunk of 
trigi.lisp can
be commented out.

------------------- untested experimental code 
---------------------------------------------------

;; Convert a Lisp complex number to a Maxima expression.

(defun lisp-complex-to-maxima (x)
  (cond ((complexp x) (add (realpart x) `((mtimes simp) $%i ,(imagpart 
x))))
        (t x)))

(defun domain-error (x fn)
  (merror "The number ~:M is not in the domain of ~:M" x fn))

;; These functions only receive real arguments, but they can 
;; return a Maxima complex number

;; Errors aren't handled gracefully -- the asec function has an 
;; play  error handler.

;; The conversions to floats might be unnecessary?

(defun acos (x)
  (lisp-complex-to-maxima (lisp:acos (float x 1.0L0))))

;; See A&S 4.4.5

(defun asec (x)
  (let ((y (ignore-errors (acos (/ x)))))
    (if (null y) (domain-error x "$asec") y)))

(defun acosh (x)
  (lisp-complex-to-maxima (lisp:acosh (float x 1.0L0))))
 
;; See A&S 4.6.5
(defun asech (x)
  (acosh (/ x)))

(defun asin (x)
  (lisp-complex-to-maxima (lisp:asin (float x 1.0L0))))

;; See A&S 4.4.6
(defun acsc (x)
  (asin (/ x)))

(defun asinh (x)
  (lisp-complex-to-maxima (lisp:asinh (float x 1.0L0))))

;; See A&S 4.6.4
(defun acsch (x)
  (asinh (/ x)))

(defun atan1 (x)
  (lisp-complex-to-maxima (lisp:atan (float x 1.0L0))))

;; See A&S 4.4.8
(defun acot (x)
  (lisp-complex-to-maxima (lisp:atan (/ (float x 1.0L0)))))

(defun atan2 (a &optional (b (float 1.0L0)))
  (lisp-complex-to-maxima (lisp:atan (float a 1.0L0) (float b 1.0L0))))

(defun atanh (x)
  (lisp-complex-to-maxima (lisp:atanh (float x 1.0L0))))

;; See A&S 4.6.6
(defun acoth (x)
  (atanh (/ x)))

(defun sec (x)
  (/ (lisp:cos (float x 1.0L0))))

(defun cosh (x)
  (lisp-complex-to-maxima (lisp:cosh (float x 1.0L0))))

(defun sech (x)
  (/ (cosh x)))

(defun csc (x)
  (/ (lisp:sin (float x 1.0L0))))

(defun sinh (x)
  (lisp-complex-to-maxima (lisp:sinh (float x 1.0L0))))

(defun csch (x)
  (/ (sinh x)))

(defun tan (x)
  (lisp-complex-to-maxima (lisp:tan (float x 1.0L0))))

(defun cot (x)
  (/ (tan x)))

(defun tanh (x)
  (lisp-complex-to-maxima (lisp:tanh (float x 1.0L0))))

(defun coth (x)
  (/ (tanh x)))


------------end of file ------------------------------------------------
Barton