base-4.16.2.0: Basic libraries

Data.Complex

Description

Complex numbers.

Synopsis

# Rectangular form

data Complex a Source #

Complex numbers are an algebraic type.

For a complex number z, abs z is a number with the magnitude of z, but oriented in the positive real direction, whereas signum z has the phase of z, but unit magnitude.

The Foldable and Traversable instances traverse the real part first.

Note that Complex's instances inherit the deficiencies from the type parameter's. For example, Complex Float's Ord instance has similar problems to Float's.

Constructors

 !a :+ !a infix 6 forms a complex number from its real and imaginary rectangular components.

#### Instances

Instances details
 Source # Since: base-4.15.0.0 Instance detailsDefined in Data.Complex Methodsmfix :: (a -> Complex a) -> Complex a Source # Source # Since: base-4.15.0.0 Instance detailsDefined in Data.Complex Methodsmzip :: Complex a -> Complex b -> Complex (a, b) Source #mzipWith :: (a -> b -> c) -> Complex a -> Complex b -> Complex c Source #munzip :: Complex (a, b) -> (Complex a, Complex b) Source # Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Complex Methodsfold :: Monoid m => Complex m -> m Source #foldMap :: Monoid m => (a -> m) -> Complex a -> m Source #foldMap' :: Monoid m => (a -> m) -> Complex a -> m Source #foldr :: (a -> b -> b) -> b -> Complex a -> b Source #foldr' :: (a -> b -> b) -> b -> Complex a -> b Source #foldl :: (b -> a -> b) -> b -> Complex a -> b Source #foldl' :: (b -> a -> b) -> b -> Complex a -> b Source #foldr1 :: (a -> a -> a) -> Complex a -> a Source #foldl1 :: (a -> a -> a) -> Complex a -> a Source #toList :: Complex a -> [a] Source #null :: Complex a -> Bool Source #length :: Complex a -> Int Source #elem :: Eq a => a -> Complex a -> Bool Source #maximum :: Ord a => Complex a -> a Source #minimum :: Ord a => Complex a -> a Source #sum :: Num a => Complex a -> a Source #product :: Num a => Complex a -> a Source # Source # >>> eq1 (1 :+ 2) (1 :+ 2) True >>> eq1 (1 :+ 2) (1 :+ 3) False Since: base-4.16.0.0 Instance detailsDefined in Data.Functor.Classes MethodsliftEq :: (a -> b -> Bool) -> Complex a -> Complex b -> Bool Source # Source # >>> readPrec_to_S readPrec1 0 "(2 % 3) :+ (3 % 4)" :: [(Complex Rational, String)] [(2 % 3 :+ 3 % 4,"")] Since: base-4.16.0.0 Instance detailsDefined in Data.Functor.Classes MethodsliftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Complex a) Source #liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Complex a] Source #liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Complex a) Source #liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Complex a] Source # Source # >>> showsPrec1 0 (2 :+ 3) "" "2 :+ 3" Since: base-4.16.0.0 Instance detailsDefined in Data.Functor.Classes MethodsliftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Complex a -> ShowS Source #liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Complex a] -> ShowS Source # Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Complex Methodstraverse :: Applicative f => (a -> f b) -> Complex a -> f (Complex b) Source #sequenceA :: Applicative f => Complex (f a) -> f (Complex a) Source #mapM :: Monad m => (a -> m b) -> Complex a -> m (Complex b) Source #sequence :: Monad m => Complex (m a) -> m (Complex a) Source # Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Complex Methodspure :: a -> Complex a Source #(<*>) :: Complex (a -> b) -> Complex a -> Complex b Source #liftA2 :: (a -> b -> c) -> Complex a -> Complex b -> Complex c Source #(*>) :: Complex a -> Complex b -> Complex b Source #(<*) :: Complex a -> Complex b -> Complex a Source # Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Complex Methodsfmap :: (a -> b) -> Complex a -> Complex b Source #(<\$) :: a -> Complex b -> Complex a Source # Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Complex Methods(>>=) :: Complex a -> (a -> Complex b) -> Complex b Source #(>>) :: Complex a -> Complex b -> Complex b Source #return :: a -> Complex a Source # Source # Instance detailsDefined in Data.Complex Associated Typestype Rep1 Complex :: k -> Type Source # Methodsfrom1 :: forall (a :: k). Complex a -> Rep1 Complex a Source #to1 :: forall (a :: k). Rep1 Complex a -> Complex a Source # Data a => Data (Complex a) Source # Since: base-2.1 Instance detailsDefined in Data.Complex Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Complex a -> c (Complex a) Source #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Complex a) Source #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Complex a)) Source #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Complex a)) Source #gmapT :: (forall b. Data b => b -> b) -> Complex a -> Complex a Source #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Complex a -> r Source #gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Complex a -> r Source #gmapQ :: (forall d. Data d => d -> u) -> Complex a -> [u] Source #gmapQi :: Int -> (forall d. Data d => d -> u) -> Complex a -> u Source #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Complex a -> m (Complex a) Source #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Complex a -> m (Complex a) Source #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Complex a -> m (Complex a) Source # Storable a => Storable (Complex a) Source # Since: base-4.8.0.0 Instance detailsDefined in Data.Complex MethodssizeOf :: Complex a -> Int Source #peekElemOff :: Ptr (Complex a) -> Int -> IO (Complex a) Source #pokeElemOff :: Ptr (Complex a) -> Int -> Complex a -> IO () Source #peekByteOff :: Ptr b -> Int -> IO (Complex a) Source #pokeByteOff :: Ptr b -> Int -> Complex a -> IO () Source #peek :: Ptr (Complex a) -> IO (Complex a) Source #poke :: Ptr (Complex a) -> Complex a -> IO () Source # RealFloat a => Floating (Complex a) Source # Since: base-2.1 Instance detailsDefined in Data.Complex Methodsexp :: Complex a -> Complex a Source #log :: Complex a -> Complex a Source #sqrt :: Complex a -> Complex a Source #(**) :: Complex a -> Complex a -> Complex a Source #logBase :: Complex a -> Complex a -> Complex a Source #sin :: Complex a -> Complex a Source #cos :: Complex a -> Complex a Source #tan :: Complex a -> Complex a Source #asin :: Complex a -> Complex a Source #acos :: Complex a -> Complex a Source #atan :: Complex a -> Complex a Source #sinh :: Complex a -> Complex a Source #cosh :: Complex a -> Complex a Source #tanh :: Complex a -> Complex a Source #asinh :: Complex a -> Complex a Source #acosh :: Complex a -> Complex a Source #atanh :: Complex a -> Complex a Source #log1p :: Complex a -> Complex a Source #expm1 :: Complex a -> Complex a Source # Source # Instance detailsDefined in Data.Complex Associated Typestype Rep (Complex a) :: Type -> Type Source # Methodsfrom :: Complex a -> Rep (Complex a) x Source #to :: Rep (Complex a) x -> Complex a Source # RealFloat a => Num (Complex a) Source # Since: base-2.1 Instance detailsDefined in Data.Complex Methods(+) :: Complex a -> Complex a -> Complex a Source #(-) :: Complex a -> Complex a -> Complex a Source #(*) :: Complex a -> Complex a -> Complex a Source #negate :: Complex a -> Complex a Source #abs :: Complex a -> Complex a Source #signum :: Complex a -> Complex a Source # Read a => Read (Complex a) Source # Since: base-2.1 Instance detailsDefined in Data.Complex Methods RealFloat a => Fractional (Complex a) Source # Since: base-2.1 Instance detailsDefined in Data.Complex Methods(/) :: Complex a -> Complex a -> Complex a Source #recip :: Complex a -> Complex a Source # Show a => Show (Complex a) Source # Since: base-2.1 Instance detailsDefined in Data.Complex MethodsshowsPrec :: Int -> Complex a -> ShowS Source #show :: Complex a -> String Source #showList :: [Complex a] -> ShowS Source # Eq a => Eq (Complex a) Source # Since: base-2.1 Instance detailsDefined in Data.Complex Methods(==) :: Complex a -> Complex a -> Bool Source #(/=) :: Complex a -> Complex a -> Bool Source # type Rep1 Complex Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Complex type Rep1 Complex = D1 ('MetaData "Complex" "Data.Complex" "base" 'False) (C1 ('MetaCons ":+" ('InfixI 'NotAssociative 6) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1 :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1)) type Rep (Complex a) Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Complex type Rep (Complex a) = D1 ('MetaData "Complex" "Data.Complex" "base" 'False) (C1 ('MetaCons ":+" ('InfixI 'NotAssociative 6) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)))

realPart :: Complex a -> a Source #

Extracts the real part of a complex number.

imagPart :: Complex a -> a Source #

Extracts the imaginary part of a complex number.

# Polar form

mkPolar :: Floating a => a -> a -> Complex a Source #

Form a complex number from polar components of magnitude and phase.

cis :: Floating a => a -> Complex a Source #

cis t is a complex value with magnitude 1 and phase t (modulo 2*pi).

polar :: RealFloat a => Complex a -> (a, a) Source #

The function polar takes a complex number and returns a (magnitude, phase) pair in canonical form: the magnitude is nonnegative, and the phase in the range (-pi, pi]; if the magnitude is zero, then so is the phase.

magnitude :: RealFloat a => Complex a -> a Source #

The nonnegative magnitude of a complex number.

phase :: RealFloat a => Complex a -> a Source #

The phase of a complex number, in the range (-pi, pi]. If the magnitude is zero, then so is the phase.

# Conjugate

conjugate :: Num a => Complex a -> Complex a Source #

The conjugate of a complex number.