planet-mitchell-0.1.0: Planet Mitchell

Num.Complex

Contents

Synopsis

# Complex

data Complex a #

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.

Instances
 Since: base-4.9.0.0 Instance detailsDefined in Data.Complex Methods(>>=) :: Complex a -> (a -> Complex b) -> Complex b #(>>) :: Complex a -> Complex b -> Complex b #return :: a -> Complex a #fail :: String -> Complex a # Instance detailsDefined in Data.Complex Methodsfmap :: (a -> b) -> Complex a -> Complex b #(<\$) :: a -> Complex b -> Complex a # Since: base-4.9.0.0 Instance detailsDefined in Data.Complex Methodspure :: a -> Complex a #(<*>) :: Complex (a -> b) -> Complex a -> Complex b #liftA2 :: (a -> b -> c) -> Complex a -> Complex b -> Complex c #(*>) :: Complex a -> Complex b -> Complex b #(<*) :: Complex a -> Complex b -> Complex a # Instance detailsDefined in Data.Complex Methodsfold :: Monoid m => Complex m -> m #foldMap :: Monoid m => (a -> m) -> Complex a -> m #foldr :: (a -> b -> b) -> b -> Complex a -> b #foldr' :: (a -> b -> b) -> b -> Complex a -> b #foldl :: (b -> a -> b) -> b -> Complex a -> b #foldl' :: (b -> a -> b) -> b -> Complex a -> b #foldr1 :: (a -> a -> a) -> Complex a -> a #foldl1 :: (a -> a -> a) -> Complex a -> a #toList :: Complex a -> [a] #null :: Complex a -> Bool #length :: Complex a -> Int #elem :: Eq a => a -> Complex a -> Bool #maximum :: Ord a => Complex a -> a #minimum :: Ord a => Complex a -> a #sum :: Num a => Complex a -> a #product :: Num a => Complex a -> a # Instance detailsDefined in Data.Complex Methodstraverse :: Applicative f => (a -> f b) -> Complex a -> f (Complex b) #sequenceA :: Applicative f => Complex (f a) -> f (Complex a) #mapM :: Monad m => (a -> m b) -> Complex a -> m (Complex b) #sequence :: Monad m => Complex (m a) -> m (Complex a) # Instance detailsDefined in Data.Distributive Methodsdistribute :: Functor f => f (Complex a) -> Complex (f a) #collect :: Functor f => (a -> Complex b) -> f a -> Complex (f b) #distributeM :: Monad m => m (Complex a) -> Complex (m a) #collectM :: Monad m => (a -> Complex b) -> m a -> Complex (m b) # Instance detailsDefined in Data.Functor.Rep Associated Typestype Rep Complex :: * # Methodstabulate :: (Rep Complex -> a) -> Complex a #index :: Complex a -> Rep Complex -> a # Instance detailsDefined in Data.Hashable.Class MethodsliftHashWithSalt :: (Int -> a -> Int) -> Int -> Complex a -> Int # Instance detailsDefined in Data.Functor.Bind.Class Methods(<.>) :: Complex (a -> b) -> Complex a -> Complex b #(.>) :: Complex a -> Complex b -> Complex b #(<.) :: Complex a -> Complex b -> Complex a #liftF2 :: (a -> b -> c) -> Complex a -> Complex b -> Complex c # Instance detailsDefined in Data.Semigroup.Traversable.Class Methodstraverse1 :: Apply f => (a -> f b) -> Complex a -> f (Complex b) #sequence1 :: Apply f => Complex (f b) -> f (Complex b) # Instance detailsDefined in Data.Semigroup.Foldable.Class Methodsfold1 :: Semigroup m => Complex m -> m #foldMap1 :: Semigroup m => (a -> m) -> Complex a -> m #toNonEmpty :: Complex a -> NonEmpty a # Instance detailsDefined in Data.Functor.Bind.Class Methods(>>-) :: Complex a -> (a -> Complex b) -> Complex b #join :: Complex (Complex a) -> Complex a # Unbox a => Vector Vector (Complex a) Instance detailsDefined in Data.Vector.Unboxed.Base MethodsbasicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (Complex a) -> m (Vector (Complex a)) #basicUnsafeThaw :: PrimMonad m => Vector (Complex a) -> m (Mutable Vector (PrimState m) (Complex a)) #basicLength :: Vector (Complex a) -> Int #basicUnsafeSlice :: Int -> Int -> Vector (Complex a) -> Vector (Complex a) #basicUnsafeIndexM :: Monad m => Vector (Complex a) -> Int -> m (Complex a) #basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (Complex a) -> Vector (Complex a) -> m () #elemseq :: Vector (Complex a) -> Complex a -> b -> b # Unbox a => MVector MVector (Complex a) Instance detailsDefined in Data.Vector.Unboxed.Base MethodsbasicLength :: MVector s (Complex a) -> Int #basicUnsafeSlice :: Int -> Int -> MVector s (Complex a) -> MVector s (Complex a) #basicOverlaps :: MVector s (Complex a) -> MVector s (Complex a) -> Bool #basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) (Complex a)) #basicInitialize :: PrimMonad m => MVector (PrimState m) (Complex a) -> m () #basicUnsafeReplicate :: PrimMonad m => Int -> Complex a -> m (MVector (PrimState m) (Complex a)) #basicUnsafeRead :: PrimMonad m => MVector (PrimState m) (Complex a) -> Int -> m (Complex a) #basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) (Complex a) -> Int -> Complex a -> m () #basicClear :: PrimMonad m => MVector (PrimState m) (Complex a) -> m () #basicSet :: PrimMonad m => MVector (PrimState m) (Complex a) -> Complex a -> m () #basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) (Complex a) -> MVector (PrimState m) (Complex a) -> m () #basicUnsafeMove :: PrimMonad m => MVector (PrimState m) (Complex a) -> MVector (PrimState m) (Complex a) -> m () #basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) (Complex a) -> Int -> m (MVector (PrimState m) (Complex a)) # Eq a => Eq (Complex a) Instance detailsDefined in Data.Complex Methods(==) :: Complex a -> Complex a -> Bool #(/=) :: Complex a -> Complex a -> Bool # RealFloat a => Floating (Complex a) Since: base-2.1 Instance detailsDefined in Data.Complex Methodspi :: Complex a #exp :: Complex a -> Complex a #log :: Complex a -> Complex a #sqrt :: Complex a -> Complex a #(**) :: Complex a -> Complex a -> Complex a #logBase :: Complex a -> Complex a -> Complex a #sin :: Complex a -> Complex a #cos :: Complex a -> Complex a #tan :: Complex a -> Complex a #asin :: Complex a -> Complex a #acos :: Complex a -> Complex a #atan :: Complex a -> Complex a #sinh :: Complex a -> Complex a #cosh :: Complex a -> Complex a #tanh :: Complex a -> Complex a #asinh :: Complex a -> Complex a #acosh :: Complex a -> Complex a #atanh :: Complex a -> Complex a #log1p :: Complex a -> Complex a #expm1 :: Complex a -> Complex a #log1pexp :: Complex a -> Complex a #log1mexp :: Complex a -> Complex a # RealFloat a => Fractional (Complex a) Since: base-2.1 Instance detailsDefined in Data.Complex Methods(/) :: Complex a -> Complex a -> Complex a #recip :: Complex a -> Complex a # Data a => Data (Complex a) 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) #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Complex a) #toConstr :: Complex a -> Constr #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Complex a)) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Complex a)) #gmapT :: (forall b. Data b => b -> b) -> Complex a -> Complex a #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Complex a -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Complex a -> r #gmapQ :: (forall d. Data d => d -> u) -> Complex a -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> Complex a -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Complex a -> m (Complex a) #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Complex a -> m (Complex a) #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Complex a -> m (Complex a) # RealFloat a => Num (Complex a) Since: base-2.1 Instance detailsDefined in Data.Complex Methods(+) :: Complex a -> Complex a -> Complex a #(-) :: Complex a -> Complex a -> Complex a #(*) :: Complex a -> Complex a -> Complex a #negate :: Complex a -> Complex a #abs :: Complex a -> Complex a #signum :: Complex a -> Complex a # Read a => Read (Complex a) Instance detailsDefined in Data.Complex MethodsreadsPrec :: Int -> ReadS (Complex a) # Show a => Show (Complex a) Instance detailsDefined in Data.Complex MethodsshowsPrec :: Int -> Complex a -> ShowS #show :: Complex a -> String #showList :: [Complex a] -> ShowS # Instance detailsDefined in Data.Complex Associated Typestype Rep (Complex a) :: * -> * # Methodsfrom :: Complex a -> Rep (Complex a) x #to :: Rep (Complex a) x -> Complex a # Hashable a => Hashable (Complex a) Instance detailsDefined in Data.Hashable.Class MethodshashWithSalt :: Int -> Complex a -> Int #hash :: Complex a -> Int # Storable a => Storable (Complex a) Since: base-4.8.0.0 Instance detailsDefined in Data.Complex MethodssizeOf :: Complex a -> Int #alignment :: Complex a -> Int #peekElemOff :: Ptr (Complex a) -> Int -> IO (Complex a) #pokeElemOff :: Ptr (Complex a) -> Int -> Complex a -> IO () #peekByteOff :: Ptr b -> Int -> IO (Complex a) #pokeByteOff :: Ptr b -> Int -> Complex a -> IO () #peek :: Ptr (Complex a) -> IO (Complex a) #poke :: Ptr (Complex a) -> Complex a -> IO () # NFData a => NFData (Complex a) Instance detailsDefined in Control.DeepSeq Methodsrnf :: Complex a -> () # Unbox a => Unbox (Complex a) Instance detailsDefined in Data.Vector.Unboxed.Base (RealFloat a, Precise a) => Precise (Complex a) Instance detailsDefined in Numeric.Log Methodslog1p :: Complex a -> Complex a #expm1 :: Complex a -> Complex a #log1pexp :: Complex a -> Complex a #log1mexp :: Complex a -> Complex a # Serialise a => Serialise (Complex a) Since: serialise-0.2.0.0 Instance detailsDefined in Codec.Serialise.Class Methodsencode :: Complex a -> Encoding #decode :: Decoder s (Complex a) #encodeList :: [Complex a] -> Encoding #decodeList :: Decoder s [Complex a] # Instance detailsDefined in Data.Complex Associated Typestype Rep1 Complex :: k -> * # Methodsfrom1 :: Complex a -> Rep1 Complex a #to1 :: Rep1 Complex a -> Complex a # (Eq a) :=> (Eq (Complex a)) Instance detailsDefined in Data.Constraint Methodsins :: Eq a :- Eq (Complex a) # (Read a) :=> (Read (Complex a)) Instance detailsDefined in Data.Constraint Methodsins :: Read a :- Read (Complex a) # (RealFloat a) :=> (Num (Complex a)) Instance detailsDefined in Data.Constraint Methods (RealFloat a) :=> (Fractional (Complex a)) Instance detailsDefined in Data.Constraint Methods (RealFloat a) :=> (Floating (Complex a)) Instance detailsDefined in Data.Constraint Methods (Show a) :=> (Show (Complex a)) Instance detailsDefined in Data.Constraint Methodsins :: Show a :- Show (Complex a) # Each (Complex a) (Complex b) a b each :: (RealFloat a, RealFloat b) => Traversal (Complex a) (Complex b) a b Instance detailsDefined in Control.Lens.Each Methodseach :: Traversal (Complex a) (Complex b) a b # type Rep Complex Instance detailsDefined in Data.Functor.Rep type Rep Complex = Bool data MVector s (Complex a) Instance detailsDefined in Data.Vector.Unboxed.Base data MVector s (Complex a) = MV_Complex (MVector s (a, a)) type Rep (Complex a) 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))) data Vector (Complex a) Instance detailsDefined in Data.Vector.Unboxed.Base data Vector (Complex a) = V_Complex (Vector (a, a)) type Index (Complex a) Instance detailsDefined in Control.Lens.At type Index (Complex a) = Int type Rep1 Complex 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))

realPart :: Complex a -> a #

Extracts the real part of a complex number.

imagPart :: Complex a -> a #

Extracts the imaginary part of a complex number.

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

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

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

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

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

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 #

The nonnegative magnitude of a complex number.

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

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

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

The conjugate of a complex number.

## Optics

_realPart :: Functor f => (a -> f a) -> Complex a -> f (Complex a) #

Access the realPart of a Complex number.

>>> (a :+ b)^._realPart
a

>>> a :+ b & _realPart *~ 2
a * 2 :+ b

_realPart :: Functor f => (a -> f a) -> Complex a -> f (Complex a)

_imagPart :: Functor f => (a -> f a) -> Complex a -> f (Complex a) #

Access the imagPart of a Complex number.

>>> (a :+ b)^._imagPart
b

>>> a :+ b & _imagPart *~ 2
a :+ b * 2

_imagPart :: Functor f => (a -> f a) -> Complex a -> f (Complex a)

_polar :: RealFloat a => Iso' (Complex a) (a, a) #

This isn't quite a legal Lens. Notably the

view l (set l b a) = b

law is violated when you set a polar value with 0 magnitude and non-zero phase as the phase information is lost, or with a negative magnitude which flips the phase and retains a positive magnitude. So don't do that!

Otherwise, this is a perfectly cromulent Lens.

_magnitude :: RealFloat a => Lens' (Complex a) a #

Access the magnitude of a Complex number.

>>> (10.0 :+ 20.0) & _magnitude *~ 2
20.0 :+ 40.0


This isn't quite a legal Lens. Notably the

view l (set l b a) = b

law is violated when you set a negative magnitude. This flips the phase and retains a positive magnitude. So don't do that!

Otherwise, this is a perfectly cromulent Lens.

Setting the magnitude of a zero Complex number assumes the phase is 0.

_phase :: RealFloat a => Lens' (Complex a) a #

Access the phase of a Complex number.

>>> (mkPolar 10 (2-pi) & _phase +~ pi & view _phase) ≈ 2
True


This isn't quite a legal Lens. Notably the

view l (set l b a) = b

law is violated when you set a phase outside the range (-pi, pi]. The phase is always in that range when queried. So don't do that!

Otherwise, this is a perfectly cromulent Lens.

_conjugate :: RealFloat a => Iso' (Complex a) (Complex a) #

Access the conjugate of a Complex number.

>>> (2.0 :+ 3.0) & _conjugate . _imagPart -~ 1
2.0 :+ 4.0

>>> (mkPolar 10.0 2.0 ^. _conjugate . _phase) ≈ (-2.0)
True