convergence of functions of Complex variables

This does not work as expected on Complex numbers due to some odd typechecking hassles apparently associated with abs. How do I get this to typecheck for both real (e.g. Double) and Complex arguments? \begin{code} module Jacobi (sn, cn, dn, sd, cd, nd, cs, ds, ns, sc, dc, nc) where scd x k | abs k < 1e-14 = (sin x, cos x, 1) | otherwise = ((1+m)*s/(1+m*s^2), c*d/(1+m*s^2), (1 - m*s^2)/(1+m*s^2)) where k' = cos $ asin k m = -tanh(log(k')/2) (s, c, d) = scd (x/(1+m)) m sn x k = let (s,_,_) = scd x k in s cn x k = let (_,c,_) = scd x k in c dn x k = let (_,_,d) = scd x k in d sd x k = (sn x k)/(dn x k) cd x k = (cn x k)/(dn x k) nd x k = 1/(dn x k) cs x k = (cn x k)/(sn x k) ds x k = (dn x k)/(sn x k) ns x k = 1/(sn x k) sc x k = (sn x k)/(cn x k) dc x k = (dn x k)/(cn x k) nc x k = 1/(cn x k) \end{code}

On Wed, Dec 15, 2004 at 02:07:10AM -0800, William Lee Irwin III wrote:
This does not work as expected on Complex numbers due to some odd typechecking hassles apparently associated with abs. How do I get this to typecheck for both real (e.g. Double) and Complex arguments?
abs :: Num a => a -> a, whereas you want something that returns a Double. You could define class Norm a where norm :: a -> Double instance Norm Float where norm = realToFrac . abs instance Norm Double where norm = abs instance RealFloat a => Norm (Complex a) where norm = realToFrac . magnitude and use norm instead of abs.

On Wed, Dec 15, 2004 at 02:07:10AM -0800, William Lee Irwin III wrote:
This does not work as expected on Complex numbers due to some odd typechecking hassles apparently associated with abs. How do I get this to typecheck for both real (e.g. Double) and Complex arguments?
On Wed, Dec 15, 2004 at 10:28:18AM +0000, Ross Paterson wrote:
abs :: Num a => a -> a, whereas you want something that returns a Double. You could define class Norm a where norm :: a -> Double instance Norm Float where norm = realToFrac . abs instance Norm Double where norm = abs instance RealFloat a => Norm (Complex a) where norm = realToFrac . magnitude and use norm instead of abs.
Thanks; this appears to do the trick for me. Something of this kind would be useful to have in the std. libraries, at least for me. -- wli

William Lee Irwin III wrote:
This does not work as expected on Complex numbers due to some odd typechecking hassles apparently associated with abs. ...
Ross Paterson wrote:
abs :: Num a => a -> a, whereas you want something that returns a Double. You could define class Norm a where norm :: a -> Double instance Norm Float where norm = realToFrac . abs instance Norm Double where norm = abs instance RealFloat a => Norm (Complex a) where norm = realToFrac . magnitude and use norm instead of abs.
Thanks; this appears to do the trick for me. Something of this kind would be useful to have in the std. libraries, at least for me.
Provided you work only with one type for norms, say, Double. In general, the construction of, say Normed Vector Spaces with any type for the ('carrier') elements, and any norm compatible with the elements would require multi-parametric classes. With dependencies, of course... Since they are not *so* old, and the numerics in Haskell have been frozen a long time ago, Haskell libraries from the math point of view evolve slowly. But people are interested in that, and the work will continue. Jerzy Karczmarczuk

On Wed, 15 Dec 2004, William Lee Irwin III wrote:
On Wed, Dec 15, 2004 at 10:28:18AM +0000, Ross Paterson wrote:
abs :: Num a => a -> a, whereas you want something that returns a Double. You could define class Norm a where norm :: a -> Double instance Norm Float where norm = realToFrac . abs instance Norm Double where norm = abs instance RealFloat a => Norm (Complex a) where norm = realToFrac . magnitude and use norm instead of abs.
Thanks; this appears to do the trick for me. Something of this kind would be useful to have in the std. libraries, at least for me.
http://cvs.haskell.org/darcs/numericprelude/physunit/Normalization.hs
participants (4)
-
Henning Thielemann
-
Jerzy Karczmarczuk
-
Ross Paterson
-
William Lee Irwin III