Commits

Aleksey Khudyakov committed 8fee4ef

Copy over small functions from old lorentz package

  • Participants
  • Parent commits a1da743

Comments (0)

Files changed (2)

Data/NVector/Lorentz.hs

                             , lorentzX
                             , lorentzY
                             , lorentzZ
-                              -- * Boosts 
+                              -- ** Convert between rapidity, gamma factor & speed
+                            , vToRapidity
+                            , vToGamma
+                            , rapidityToGamma
+                            , rapidityToV
+                            , gammaToV
+                            , gammaToRapidity
+                              -- * Boosts
                               -- ** One dimesional boosts
                             , Boost1D
                             , inverseBoost1D
+                              -- *** Constructors and accessors
+                            , rapidityBoost1D
+                            , boost1Drapidity
+                            , gammaBoost1D
+                            , boost1Dgamma
+                            , vBoost1D
+                            , boost1Dv
                             ) where
 
 import qualified Data.Vector.Unboxed as U
 type Lorentz n a = N.NVector LorentzTag n a
 
 -- | Extract spatial part from Lorentz vector
-spatialPart :: (U.Unbox a, Nat n, Nat (Prev n), Positive (Prev n)) 
+spatialPart :: (U.Unbox a, Nat n, Nat (Prev n), Positive (Prev n))
             => Lorentz n a -> Euclidean (Prev n) a
 spatialPart = N.tail . N.unsafeTypeCast
 
 instance (Nat n, Greater n N1, Num a, U.Unbox a)
          => AdditiveGroup (Lorentz n a) where
     zeroV   = N.replicate 0
-    (^+^)   = N.zipWith (+) 
+    (^+^)   = N.zipWith (+)
     negateV = N.map negate
 
-instance (Nat n, Greater n N1, Num a, U.Unbox a) 
+instance (Nat n, Greater n N1, Num a, U.Unbox a)
          => VectorSpace (Lorentz n a) where
     type Scalar (Lorentz n a) = a
     x *^ v = N.map (x*) v
 
-instance (Nat n, Nat (Prev n), Greater n N1, Num a, U.Unbox a) 
+instance (Nat n, Nat (Prev n), Greater n N1, Num a, U.Unbox a)
          => InnerSpace (Lorentz n a) where
     v1 <.> v2 = (v1 ! 0) * (v2 ! 0) - N.sum (N.zipWith (*) (N.tail v1') (N.tail v2'))
-      where 
+      where
         -- Remove type tag. Lets work with raw numbers
         v1' = N.stripTypeTag v1
         v2' = N.stripTypeTag v2
 
+----------------------------------------------------------------
+-- Conversions
+----------------------------------------------------------------
+
+-- | Convert speed to rapidity
+vToRapidity :: Floating a => a -> a
+vToRapidity = atanh
+
+-- | Convert speed in speed of light units to gamma factor
+vToGamma :: Floating a => a -> a
+vToGamma v = 1 / sqrt( 1 - v**2 )
+
+-- | Convert rapidity to gamma factor
+rapidityToGamma :: Floating a => a -> a
+rapidityToGamma = cosh
+
+-- | Convert rapidity to speed
+rapidityToV :: Floating a => a -> a
+rapidityToV = tanh
+
+-- | Convert gamma factor to speed
+gammaToV :: Floating a => a -> a
+gammaToV g = sqrt( (g**2 - 1)/ g**2 )
+
+-- | Convert gamma factor to rapidity
+gammaToRapidity :: Floating a => a -> a
+gammaToRapidity = acosh
 
 ----------------------------------------------------------------
 -- Boosts
 -- | Create inverse boost
 inverseBoost1D :: Num a => Boost1D a -> Boost1D a
 inverseBoost1D (Boost1D x) = Boost1D (negate x)
+
+
+----------------------------------------------------------------
+-- Constructors and accessors
+
+-- | Create 1D boost from rapidity
+rapidityBoost1D :: Floating a => a -> Boost1D a
+rapidityBoost1D = Boost1D
+
+-- | Get rapidity from 1D boost
+boost1Drapidity :: Floating a => Boost1D a -> a
+boost1Drapidity (Boost1D x) = x
+
+-- | construct boost from gamma factor
+gammaBoost1D :: Floating a => a -> Boost1D a
+gammaBoost1D = Boost1D . gammaToRapidity
+
+-- | Get gamma factor which correspond to boost
+boost1Dgamma :: Floating a => Boost1D a -> a
+boost1Dgamma (Boost1D x) = rapidityToGamma x
+
+-- | Construct boost from speed 
+vBoost1D :: Floating a => a -> Boost1D a 
+vBoost1D = Boost1D . vToRapidity
+
+-- | Get speed
+boost1Dv :: Floating a => Boost1D a -> a
+boost1Dv (Boost1D x) = rapidityToV x

nvector-types.cabal

                    vector-space >= 0.5,
                    type-numbers
   Exposed-modules: Data.NVector.Euclidean
+                   Data.NVector.Lorentz