{-# LANGUAGE CPP, TypeOperators, TypeFamilies #-}
{-# LANGUAGE DeriveFunctor, DeriveDataTypeable #-}
{-# OPTIONS_GHC -Wall #-}

-- {-# OPTIONS_GHC -fno-warn-unused-imports #-} -- TEMP
-- {-# OPTIONS_GHC -fno-warn-unused-binds   #-} -- TEMP

#define CustomComplex

#if !defined CustomComplex
{-# OPTIONS_GHC -fno-warn-orphans #-} -- for HasRep
#endif

----------------------------------------------------------------------
-- |
-- Module      :  ConCat.Complex
-- Copyright   :  (c) 2015 Conal Elliott and David Banas
-- License     :  BSD3
--
-- Maintainer  :  conal@conal.net
-- Stability   :  experimental
--
-- Simplified Complex type
----------------------------------------------------------------------

module ConCat.Complex (Complex(..),cis) where

#if defined CustomComplex
import Control.Applicative (liftA2)
import Data.Typeable
import Data.Data
import Test.QuickCheck (Arbitrary(..),CoArbitrary(..))
#else
import Data.Complex
#endif

#if defined CustomComplex
infixl 1 :+
data Complex a = a :+ a deriving ((forall a b. (a -> b) -> Complex a -> Complex b)
-> (forall a b. a -> Complex b -> Complex a) -> Functor Complex
forall a b. a -> Complex b -> Complex a
forall a b. (a -> b) -> Complex a -> Complex b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Complex a -> Complex b
fmap :: forall a b. (a -> b) -> Complex a -> Complex b
$c<$ :: forall a b. a -> Complex b -> Complex a
<$ :: forall a b. a -> Complex b -> Complex a
Functor,Complex a -> Complex a -> Bool
(Complex a -> Complex a -> Bool)
-> (Complex a -> Complex a -> Bool) -> Eq (Complex a)
forall a. Eq a => Complex a -> Complex a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Complex a -> Complex a -> Bool
== :: Complex a -> Complex a -> Bool
$c/= :: forall a. Eq a => Complex a -> Complex a -> Bool
/= :: Complex a -> Complex a -> Bool
Eq,Int -> Complex a -> ShowS
[Complex a] -> ShowS
Complex a -> String
(Int -> Complex a -> ShowS)
-> (Complex a -> String)
-> ([Complex a] -> ShowS)
-> Show (Complex a)
forall a. Show a => Int -> Complex a -> ShowS
forall a. Show a => [Complex a] -> ShowS
forall a. Show a => Complex a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Complex a -> ShowS
showsPrec :: Int -> Complex a -> ShowS
$cshow :: forall a. Show a => Complex a -> String
show :: Complex a -> String
$cshowList :: forall a. Show a => [Complex a] -> ShowS
showList :: [Complex a] -> ShowS
Show,Typeable,Typeable (Complex a)
Typeable (Complex a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Complex a -> c (Complex a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Complex a))
-> (Complex a -> Constr)
-> (Complex a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Complex a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (Complex a)))
-> ((forall b. Data b => b -> b) -> Complex a -> Complex a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Complex a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Complex a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Complex a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Complex a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Complex a -> m (Complex a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Complex a -> m (Complex a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Complex a -> m (Complex a))
-> Data (Complex a)
Complex a -> Constr
Complex a -> DataType
(forall b. Data b => b -> b) -> Complex a -> Complex a
forall {a}. Data a => Typeable (Complex a)
forall a. Data a => Complex a -> Constr
forall a. Data a => Complex a -> DataType
forall a.
Data a =>
(forall b. Data b => b -> b) -> Complex a -> Complex a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Complex a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> Complex a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Complex a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Complex a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Complex a -> m (Complex a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Complex a -> m (Complex a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Complex a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Complex a -> c (Complex a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Complex a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Complex a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Complex a -> u
forall u. (forall d. Data d => d -> u) -> Complex a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Complex a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Complex a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Complex a -> m (Complex a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Complex a -> m (Complex a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Complex a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Complex a -> c (Complex a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Complex a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Complex a))
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Complex a -> c (Complex a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Complex a -> c (Complex a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Complex a)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Complex a)
$ctoConstr :: forall a. Data a => Complex a -> Constr
toConstr :: Complex a -> Constr
$cdataTypeOf :: forall a. Data a => Complex a -> DataType
dataTypeOf :: Complex a -> DataType
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Complex a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Complex a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Complex a))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Complex a))
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> Complex a -> Complex a
gmapT :: (forall b. Data b => b -> b) -> Complex a -> Complex a
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Complex a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Complex a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Complex a -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Complex a -> r
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> Complex a -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Complex a -> [u]
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Complex a -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Complex a -> u
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Complex a -> m (Complex a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Complex a -> m (Complex a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Complex a -> m (Complex a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Complex a -> m (Complex a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Complex a -> m (Complex a)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Complex a -> m (Complex a)
Data,Eq (Complex a)
Eq (Complex a)
-> (Complex a -> Complex a -> Ordering)
-> (Complex a -> Complex a -> Bool)
-> (Complex a -> Complex a -> Bool)
-> (Complex a -> Complex a -> Bool)
-> (Complex a -> Complex a -> Bool)
-> (Complex a -> Complex a -> Complex a)
-> (Complex a -> Complex a -> Complex a)
-> Ord (Complex a)
Complex a -> Complex a -> Bool
Complex a -> Complex a -> Ordering
Complex a -> Complex a -> Complex a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (Complex a)
forall a. Ord a => Complex a -> Complex a -> Bool
forall a. Ord a => Complex a -> Complex a -> Ordering
forall a. Ord a => Complex a -> Complex a -> Complex a
$ccompare :: forall a. Ord a => Complex a -> Complex a -> Ordering
compare :: Complex a -> Complex a -> Ordering
$c< :: forall a. Ord a => Complex a -> Complex a -> Bool
< :: Complex a -> Complex a -> Bool
$c<= :: forall a. Ord a => Complex a -> Complex a -> Bool
<= :: Complex a -> Complex a -> Bool
$c> :: forall a. Ord a => Complex a -> Complex a -> Bool
> :: Complex a -> Complex a -> Bool
$c>= :: forall a. Ord a => Complex a -> Complex a -> Bool
>= :: Complex a -> Complex a -> Bool
$cmax :: forall a. Ord a => Complex a -> Complex a -> Complex a
max :: Complex a -> Complex a -> Complex a
$cmin :: forall a. Ord a => Complex a -> Complex a -> Complex a
min :: Complex a -> Complex a -> Complex a
Ord)

-- | The nonnegative magnitude of a complex number.
-- {-# SPECIALISE magnitude :: Complex Double -> Double #-}
magnitude :: (RealFloat a) => Complex a -> a

magnitude :: forall a. RealFloat a => Complex a -> a
magnitude (a
x:+a
y) = a -> a
forall a. Floating a => a -> a
sqrt (a
xa -> a -> a
forall a. Num a => a -> a -> a
*a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
ya -> a -> a
forall a. Num a => a -> a -> a
*a
y)

-- From Data.Complex

-- magnitude (x:+y) =  scaleFloat k
--                      (sqrt (sqr (scaleFloat mk x) + sqr (scaleFloat mk y)))
--                     where k  = max (exponent x) (exponent y)
--                           mk = - k
--                           sqr z = z * z

-- | The phase of a complex number, in the range @(-'pi', 'pi']@.
-- If the magnitude is zero, then so is the phase.
-- {-# SPECIALISE phase :: Complex Double -> Double #-}
phase :: (RealFloat a) => Complex a -> a
phase :: forall a. RealFloat a => Complex a -> a
phase (a
0 :+ a
0)   = a
0            -- SLPJ July 97 from John Peterson
phase (a
x:+a
y)     = a -> a -> a
forall a. RealFloat a => a -> a -> a
atan2 a
y a
x

-- | Complex Identity Scaler
-- Returns a point on the unit circle, such that the angle between the
-- vector to that point and the positive x-axis is equal to the function
-- argument, given in radians.
cis :: (RealFloat a) => a -> Complex a
cis :: forall a. RealFloat a => a -> Complex a
cis a
w = a -> a
forall a. Floating a => a -> a
cos a
w a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a -> a
forall a. Floating a => a -> a
sin a
w

instance  (RealFloat a) => Num (Complex a)  where
    -- {-# SPECIALISE instance Num (Complex Float) #-}
    -- {-# SPECIALISE instance Num (Complex Double) #-}
    (a
x:+a
y) + :: Complex a -> Complex a -> Complex a
+ (a
x':+a
y')   =  (a
xa -> a -> a
forall a. Num a => a -> a -> a
+a
x') a -> a -> Complex a
forall a. a -> a -> Complex a
:+ (a
ya -> a -> a
forall a. Num a => a -> a -> a
+a
y')
    (a
x:+a
y) - :: Complex a -> Complex a -> Complex a
- (a
x':+a
y')   =  (a
xa -> a -> a
forall a. Num a => a -> a -> a
-a
x') a -> a -> Complex a
forall a. a -> a -> Complex a
:+ (a
ya -> a -> a
forall a. Num a => a -> a -> a
-a
y')
    (a
x:+a
y) * :: Complex a -> Complex a -> Complex a
* (a
x':+a
y')   =  (a
xa -> a -> a
forall a. Num a => a -> a -> a
*a
x'a -> a -> a
forall a. Num a => a -> a -> a
-a
ya -> a -> a
forall a. Num a => a -> a -> a
*a
y') a -> a -> Complex a
forall a. a -> a -> Complex a
:+ (a
xa -> a -> a
forall a. Num a => a -> a -> a
*a
y'a -> a -> a
forall a. Num a => a -> a -> a
+a
ya -> a -> a
forall a. Num a => a -> a -> a
*a
x')
    negate :: Complex a -> Complex a
negate (a
x:+a
y)       =  a -> a
forall a. Num a => a -> a
negate a
x a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a -> a
forall a. Num a => a -> a
negate a
y
    abs :: Complex a -> Complex a
abs Complex a
z               =  Complex a -> a
forall a. RealFloat a => Complex a -> a
magnitude Complex a
z a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a
0
    signum :: Complex a -> Complex a
signum (a
0:+a
0)       =  Complex a
0
    signum z :: Complex a
z@(a
x:+a
y)     =  a
xa -> a -> a
forall a. Fractional a => a -> a -> a
/a
r a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a
ya -> a -> a
forall a. Fractional a => a -> a -> a
/a
r  where r :: a
r = Complex a -> a
forall a. RealFloat a => Complex a -> a
magnitude Complex a
z
    fromInteger :: Integer -> Complex a
fromInteger Integer
n       =  Integer -> a
forall a. Num a => Integer -> a
fromInteger Integer
n a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a
0
    {-# INLINE (+)         #-}
    {-# INLINE (-)         #-}
    {-# INLINE (*)         #-}
    {-# INLINE negate      #-}
    {-# INLINE abs         #-}
    {-# INLINE signum      #-}
    {-# INLINE fromInteger #-}

instance  (RealFloat a) => Fractional (Complex a)  where
    -- {-# SPECIALISE instance Fractional (Complex Float) #-}
    -- {-# SPECIALISE instance Fractional (Complex Double) #-}
    recip :: Complex a -> Complex a
recip z :: Complex a
z@(a
x:+a
y) = a
xa -> a -> a
forall a. Fractional a => a -> a -> a
/a
mag a -> a -> Complex a
forall a. a -> a -> Complex a
:+ (-a
y)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
mag where mag :: a
mag = Complex a -> a
forall a. RealFloat a => Complex a -> a
magnitude Complex a
z
--     (x:+y) / (x':+y')   =  (x*x''+y*y'') / d :+ (y*x''-x*y'') / d
--                            where x'' = scaleFloat k x'
--                                  y'' = scaleFloat k y'
--                                  k   = - max (exponent x') (exponent y')
--                                  d   = x'*x'' + y'*y''

    fromRational :: Rational -> Complex a
fromRational Rational
a      =  Rational -> a
forall a. Fractional a => Rational -> a
fromRational Rational
a a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a
0

instance  (RealFloat a) => Floating (Complex a) where
    -- {-# SPECIALISE instance Floating (Complex Float) #-}
    -- {-# SPECIALISE instance Floating (Complex Double) #-}
    pi :: Complex a
pi             =  a
forall a. Floating a => a
pi a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a
0
    exp :: Complex a -> Complex a
exp (a
x:+a
y)     =  a
expx a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Floating a => a -> a
cos a
y a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a
expx a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Floating a => a -> a
sin a
y
                      where expx :: a
expx = a -> a
forall a. Floating a => a -> a
exp a
x
    log :: Complex a -> Complex a
log Complex a
z          =  a -> a
forall a. Floating a => a -> a
log (Complex a -> a
forall a. RealFloat a => Complex a -> a
magnitude Complex a
z) a -> a -> Complex a
forall a. a -> a -> Complex a
:+ Complex a -> a
forall a. RealFloat a => Complex a -> a
phase Complex a
z

    sqrt :: Complex a -> Complex a
sqrt (a
0:+a
0)    =  Complex a
0
    sqrt z :: Complex a
z@(a
x:+a
y)  =  a
u a -> a -> Complex a
forall a. a -> a -> Complex a
:+ (if a
y a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0 then -a
v else a
v)
                      where (a
u,a
v) = if a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0 then (a
v',a
u') else (a
u',a
v')
                            v' :: a
v'    = a -> a
forall a. Num a => a -> a
abs a
y a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
u'a -> a -> a
forall a. Num a => a -> a -> a
*a
2)
                            u' :: a
u'    = a -> a
forall a. Floating a => a -> a
sqrt ((Complex a -> a
forall a. RealFloat a => Complex a -> a
magnitude Complex a
z a -> a -> a
forall a. Num a => a -> a -> a
+ a -> a
forall a. Num a => a -> a
abs a
x) a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
2)

    sin :: Complex a -> Complex a
sin (a
x:+a
y)     =  a -> a
forall a. Floating a => a -> a
sin a
x a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Floating a => a -> a
cosh a
y a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a -> a
forall a. Floating a => a -> a
cos a
x a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Floating a => a -> a
sinh a
y
    cos :: Complex a -> Complex a
cos (a
x:+a
y)     =  a -> a
forall a. Floating a => a -> a
cos a
x a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Floating a => a -> a
cosh a
y a -> a -> Complex a
forall a. a -> a -> Complex a
:+ (- a -> a
forall a. Floating a => a -> a
sin a
x a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Floating a => a -> a
sinh a
y)
    tan :: Complex a -> Complex a
tan (a
x:+a
y)     =  (a
sinxa -> a -> a
forall a. Num a => a -> a -> a
*a
coshya -> a -> Complex a
forall a. a -> a -> Complex a
:+a
cosxa -> a -> a
forall a. Num a => a -> a -> a
*a
sinhy)Complex a -> Complex a -> Complex a
forall a. Fractional a => a -> a -> a
/(a
cosxa -> a -> a
forall a. Num a => a -> a -> a
*a
coshya -> a -> Complex a
forall a. a -> a -> Complex a
:+(-a
sinxa -> a -> a
forall a. Num a => a -> a -> a
*a
sinhy))
                      where sinx :: a
sinx  = a -> a
forall a. Floating a => a -> a
sin a
x
                            cosx :: a
cosx  = a -> a
forall a. Floating a => a -> a
cos a
x
                            sinhy :: a
sinhy = a -> a
forall a. Floating a => a -> a
sinh a
y
                            coshy :: a
coshy = a -> a
forall a. Floating a => a -> a
cosh a
y

    sinh :: Complex a -> Complex a
sinh (a
x:+a
y)    =  a -> a
forall a. Floating a => a -> a
cos a
y a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Floating a => a -> a
sinh a
x a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a -> a
forall a. Floating a => a -> a
sin  a
y a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Floating a => a -> a
cosh a
x
    cosh :: Complex a -> Complex a
cosh (a
x:+a
y)    =  a -> a
forall a. Floating a => a -> a
cos a
y a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Floating a => a -> a
cosh a
x a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a -> a
forall a. Floating a => a -> a
sin a
y a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Floating a => a -> a
sinh a
x
    tanh :: Complex a -> Complex a
tanh (a
x:+a
y)    =  (a
cosya -> a -> a
forall a. Num a => a -> a -> a
*a
sinhxa -> a -> Complex a
forall a. a -> a -> Complex a
:+a
sinya -> a -> a
forall a. Num a => a -> a -> a
*a
coshx)Complex a -> Complex a -> Complex a
forall a. Fractional a => a -> a -> a
/(a
cosya -> a -> a
forall a. Num a => a -> a -> a
*a
coshxa -> a -> Complex a
forall a. a -> a -> Complex a
:+a
sinya -> a -> a
forall a. Num a => a -> a -> a
*a
sinhx)
                      where siny :: a
siny  = a -> a
forall a. Floating a => a -> a
sin a
y
                            cosy :: a
cosy  = a -> a
forall a. Floating a => a -> a
cos a
y
                            sinhx :: a
sinhx = a -> a
forall a. Floating a => a -> a
sinh a
x
                            coshx :: a
coshx = a -> a
forall a. Floating a => a -> a
cosh a
x

    asin :: Complex a -> Complex a
asin z :: Complex a
z@(a
x:+a
y)  =  a
y'a -> a -> Complex a
forall a. a -> a -> Complex a
:+(-a
x')
                      where  (a
x':+a
y') = Complex a -> Complex a
forall a. Floating a => a -> a
log (((-a
y)a -> a -> Complex a
forall a. a -> a -> Complex a
:+a
x) Complex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
+ Complex a -> Complex a
forall a. Floating a => a -> a
sqrt (Complex a
1 Complex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
- Complex a
zComplex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
*Complex a
z))
    acos :: Complex a -> Complex a
acos Complex a
z         =  a
y''a -> a -> Complex a
forall a. a -> a -> Complex a
:+(-a
x'')
                      where (a
x'':+a
y'') = Complex a -> Complex a
forall a. Floating a => a -> a
log (Complex a
z Complex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
+ ((-a
y')a -> a -> Complex a
forall a. a -> a -> Complex a
:+a
x'))
                            (a
x':+a
y')   = Complex a -> Complex a
forall a. Floating a => a -> a
sqrt (Complex a
1 Complex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
- Complex a
zComplex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
*Complex a
z)
    atan :: Complex a -> Complex a
atan z :: Complex a
z@(a
x:+a
y)  =  a
y'a -> a -> Complex a
forall a. a -> a -> Complex a
:+(-a
x')
                      where (a
x':+a
y') = Complex a -> Complex a
forall a. Floating a => a -> a
log (((a
1a -> a -> a
forall a. Num a => a -> a -> a
-a
y)a -> a -> Complex a
forall a. a -> a -> Complex a
:+a
x) Complex a -> Complex a -> Complex a
forall a. Fractional a => a -> a -> a
/ Complex a -> Complex a
forall a. Floating a => a -> a
sqrt (Complex a
1Complex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
+Complex a
zComplex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
*Complex a
z))

    asinh :: Complex a -> Complex a
asinh Complex a
z        =  Complex a -> Complex a
forall a. Floating a => a -> a
log (Complex a
z Complex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
+ Complex a -> Complex a
forall a. Floating a => a -> a
sqrt (Complex a
1Complex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
+Complex a
zComplex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
*Complex a
z))
    acosh :: Complex a -> Complex a
acosh Complex a
z        =  Complex a -> Complex a
forall a. Floating a => a -> a
log (Complex a
z Complex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
+ (Complex a
zComplex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
+Complex a
1) Complex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
* Complex a -> Complex a
forall a. Floating a => a -> a
sqrt ((Complex a
zComplex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
-Complex a
1)Complex a -> Complex a -> Complex a
forall a. Fractional a => a -> a -> a
/(Complex a
zComplex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
+Complex a
1)))
    atanh :: Complex a -> Complex a
atanh Complex a
z        =  Complex a
0.5 Complex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
* Complex a -> Complex a
forall a. Floating a => a -> a
log ((Complex a
1.0Complex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
+Complex a
z) Complex a -> Complex a -> Complex a
forall a. Fractional a => a -> a -> a
/ (Complex a
1.0Complex a -> Complex a -> Complex a
forall a. Num a => a -> a -> a
-Complex a
z))

instance Arbitrary a => Arbitrary (Complex a) where
  arbitrary :: Gen (Complex a)
arbitrary = (a -> a -> Complex a) -> Gen a -> Gen a -> Gen (Complex a)
forall a b c. (a -> b -> c) -> Gen a -> Gen b -> Gen c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> Complex a
forall a. a -> a -> Complex a
(:+) Gen a
forall a. Arbitrary a => Gen a
arbitrary Gen a
forall a. Arbitrary a => Gen a
arbitrary
  shrink :: Complex a -> [Complex a]
shrink (a
x :+ a
y) = ((a, a) -> Complex a) -> [(a, a)] -> [Complex a]
forall a b. (a -> b) -> [a] -> [b]
map ((a -> a -> Complex a) -> (a, a) -> Complex a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> a -> Complex a
forall a. a -> a -> Complex a
(:+)) ((a, a) -> [(a, a)]
forall a. Arbitrary a => a -> [a]
shrink (a
x,a
y))

instance CoArbitrary a => CoArbitrary (Complex a) where
  coarbitrary :: forall b. Complex a -> Gen b -> Gen b
coarbitrary (a
x :+ a
y) = a -> Gen b -> Gen b
forall b. a -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary a
x (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Gen b -> Gen b
forall b. a -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary a
y

#endif