packages feed

cyclotomic 1.0.1 → 1.1.0

raw patch · 2 files changed

+27/−26 lines, 2 filesdep ~arithmoiPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: arithmoi

API changes (from Hackage documentation)

Files

cyclotomic.cabal view
@@ -1,5 +1,5 @@ Name:                cyclotomic-Version:             1.0.1+Version:             1.1.0 Stability:           stable Synopsis:            A subfield of the complex numbers for exact calculation. Description:         The cyclotomic numbers are a subset of the@@ -17,7 +17,7 @@ License-file:        LICENSE Author:              Scott N. Walck Maintainer:          Scott N. Walck <walck@lvc.edu>-Copyright:           (c) Scott N. Walck 2012-2019+Copyright:           (c) Scott N. Walck 2012-2020 Category:            Math Build-type:          Simple Extra-source-files:  test/Properties.hs@@ -39,7 +39,7 @@   Exposed-modules:   Data.Complex.Cyclotomic, Data.Number.RealCyclotomic   Build-depends:     base >= 4.2 && < 4.14,                      containers >= 0.3,-                     arithmoi >= 0.5+                     arithmoi >= 0.9   default-language:  Haskell2010   Hs-source-dirs:    src 
src/Data/Complex/Cyclotomic.hs view
@@ -1,7 +1,7 @@ {-# OPTIONS_GHC -Wall #-} {-# LANGUAGE Trustworthy #-} -{- | +{- | Module      :  Data.Complex.Cyclotomic Copyright   :  (c) Scott N. Walck 2012-2017 License     :  GPL-3 (see LICENSE)@@ -10,23 +10,23 @@  The cyclotomic numbers are a subset of the complex numbers with the following properties:-    +      1.  The cyclotomic numbers are represented exactly, enabling exact      computations and equality comparisons.-    +      2.  The cyclotomic numbers contain the Gaussian rationals      (complex numbers of the form 'p' + 'q' 'i' with 'p' and 'q' rational).      As a consequence, the cyclotomic numbers are a dense subset of the      complex numbers.-    +      3.  The cyclotomic numbers contain the square roots of all rational numbers.-    +      4.  The cyclotomic numbers form a field:  they are closed under addition, subtraction,      multiplication, and division.-    +      5.  The cyclotomic numbers contain the sine and cosine of all rational      multiples of pi.-    +      6.  The cyclotomic numbers can be thought of as the rational field extended      with 'n'th roots of unity for arbitrarily large integers 'n'. @@ -121,9 +121,16 @@     , findWithDefault     , fromListWith     )-import Math.NumberTheory.Primes.Factorisation-    ( factorise+import Math.NumberTheory.ArithmeticFunctions+    ( runFunction+    , totientA+    , smallOmegaA+    , isNFreeA     )+import Math.NumberTheory.Primes+    ( unPrime+    , factorise+    )  -- | A cyclotomic number. data Cyclotomic = Cyclotomic { order  :: Integer@@ -223,8 +230,8 @@ sqrtPositiveInteger n     | n < 1      = error "sqrtPositiveInteger needs a positive integer"     | otherwise  = let factors = factorise n-                       factor = product [p^(m `div` 2) | (p,m) <- factors]-                       nn     = product [p^(m `mod` 2) | (p,m) <- factors]+                       factor = product [unPrime p ^ (m `div` 2) | (p, m) <- factors]+                       nn     = product [unPrime p ^ (m `mod` 2) | (p, m) <- factors]                    in case nn `mod` 4 of                         1 -> fromInteger factor * (2 * eb nn + 1)                         2 -> fromInteger factor * sqrt2 * sqrtPositiveInteger (nn `div` 2)@@ -344,14 +351,8 @@       (phi,nrp,sqfree) = phiNrpSqfree (order c)  -- | Compute phi(n), the number of prime factors, and test if n is square-free.---   We do these all together for efficiency, so we only call factorise once.-phiNrpSqfree :: Integer -> (Integer,Int,Bool)-phiNrpSqfree n = (phi,nrp,sqfree)-    where-      factors = factorise n-      phi = foldr (\p n' -> n' `div` p * (p-1)) n [p | (p,_) <- factors]-      nrp = length factors-      sqfree = all (<=1) [m | (_,m) <- factors]+phiNrpSqfree :: Integer -> (Integer, Int, Bool)+phiNrpSqfree = runFunction $ (,,) <$> totientA <*> smallOmegaA <*> isNFreeA 2  equalCoefficients :: Cyclotomic -> Maybe Rational equalCoefficients (Cyclotomic _ mp)@@ -369,7 +370,7 @@ tryReduce c     = foldr reduceByPrime c squareFreeOddFactors       where-        squareFreeOddFactors = [p | (p,m) <- factorise (order c), p > 2, m <= 1]+        squareFreeOddFactors = [unPrime p | (p, m) <- factorise (order c), unPrime p > 2, m <= 1]  reduceByPrime :: Integer -> Cyclotomic -> Cyclotomic reduceByPrime p c@(Cyclotomic n _)@@ -401,12 +402,12 @@ removeExps n p q = concatMap (includeMods n q) $ map ((n `div` q) *) [-m..m]     where m = (q `div` p - 1) `div` 2 -pqPairs :: Integer -> [(Integer,Integer)]-pqPairs n = map (\(p,k) -> (p,p^k)) (factorise n)+pqPairs :: Integer -> [(Integer, Integer)]+pqPairs n = map (\(p, k) -> (unPrime p, unPrime p ^ k)) (factorise n)  extraneousPowers :: Integer -> [(Integer,Integer)] extraneousPowers n-    | n < 1      = error "extraneousPowers needs a postive integer"+    | n < 1      = error "extraneousPowers needs a positive integer"     | otherwise  = nub $ concat [[(p,r) | r <- removeExps n p q] | (p,q) <- pqPairs n]  -- | Sum of two cyclotomic numbers.