cayley-dickson 0.1.2.0 → 0.1.3.0
raw patch · 3 files changed
+23/−9 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Math.CayleyDickson: polar :: (Tag n, Conjugable a, Floating a, Ord a) => Nion n a -> (a, a, Nion n a)
+ Math.CayleyDickson: polar :: (Tag n, Conjugable a, RealFloat a) => Nion n a -> (a, a, Nion n a)
Files
- cayley-dickson.cabal +2/−1
- src/Math/CayleyDickson.hs +16/−8
- test/test.hs +5/−0
cayley-dickson.cabal view
@@ -1,5 +1,5 @@ name: cayley-dickson-version: 0.1.2.0+version: 0.1.3.0 synopsis: Complex numbers, quaternions, octonions, sedenions, etc. description: Cayley-Dickson constructions (complex numbers, quaternions, octonions, sedenions, etc.) over general scalars without@@ -14,6 +14,7 @@ extra-source-files: README.md cabal-version: >=1.10 homepage: https://github.com/lmj/cayley-dickson+bug-reports: https://github.com/lmj/cayley-dickson/issues source-repository head type: git
src/Math/CayleyDickson.hs view
@@ -226,12 +226,16 @@ ---------------------------------------------------------- -- polar form and complex function application -polarUsing :: (Conjugable a, Floating a, Ord a) =>+realPolar :: RealFloat a => Nion n a -> a -> (a, a, Nion n a)+realPolar sqrtMinus1 r+ | r >= 0 = (r, 0, sqrtMinus1)+ | otherwise = (-r, pi, sqrtMinus1)++polarUsing :: (Conjugable a, RealFloat a) => Nion n a -> Nion n a -> (a, a, Nion n a)+polarUsing sqrtMinus1 (Scalar r) = realPolar sqrtMinus1 r polarUsing sqrtMinus1 x- | sqnormp == 0 = if r >= 0- then (r, 0, sqrtMinus1)- else (-r, pi, sqrtMinus1)+ | sqnormp == 0 = realPolar sqrtMinus1 r | otherwise = (absx, acos (r / absx), u) where r = scalarPart x@@ -239,6 +243,12 @@ u = purePart x /. (sqrt sqnormp) absx = norm x +polar' :: (Tag n, Conjugable a, RealFloat a) =>+ Proxy n -> Nion n a -> (a, a, Nion n a)+polar' n x+ | tagVal n == 0 = error "polar: no polar form in 1 dimension"+ | otherwise = polarUsing basisElement1 x+ -- | Return @(s, t, u)@ such that (approximately) -- -- @x == s .* 'exp' (t .* u)@@@ -247,10 +257,8 @@ -- -- If @x@ has no pure part then @u@ is arbitrarily chosen to be the -- first pure basis element.-polar :: (Tag n, Conjugable a, Floating a, Ord a) =>- Nion n a -> (a, a, Nion n a)-polar (Scalar _) = error "polar: no polar form for scalars"-polar x = polarUsing basisElement1 x+polar :: (Tag n, Conjugable a, RealFloat a) => Nion n a -> (a, a, Nion n a)+polar = polar' Proxy applyUsing :: (Conjugable a, RealFloat a) => Nion n a -> (a -> a) -> (C.Complex a -> C.Complex a) ->
test/test.hs view
@@ -243,6 +243,11 @@ assert $ (quaternion 1 2 3 4 :: Quaternion (Ratio Integer)) /. 2 == nion [1 % 2, 1, 3 % 2, 2] + forM_ [-2, -1, -0.5, 0, 0.5, 1, 2] $ \r -> do+ let (s, t, u) = polar $ (fromScalar r :: Quaternion Double)+ assert $ s >= 0+ assertClose (fromScalar r) $ s .* exp (t .* u)+ checkInverses :: IO () checkInverses = do f $ (nion [0.1] :: Nion Tag0 Double)