summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScottWalck <>2020-05-22 14:02:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2020-05-22 14:02:00 (GMT)
commitffcf1e54ac0ec2f005f24709cc2cfedfcee94016 (patch)
treecce5cab5cacc54fda4f2fe747a62dbbbe3a0119e
parent0645c2bb91ed841add056532d727856fbda1acc6 (diff)
version 1.1.01.1.0
-rw-r--r--cyclotomic.cabal6
-rw-r--r--src/Data/Complex/Cyclotomic.hs47
2 files changed, 27 insertions, 26 deletions
diff --git a/cyclotomic.cabal b/cyclotomic.cabal
index 92406ba..dd56e0f 100644
--- a/cyclotomic.cabal
+++ b/cyclotomic.cabal
@@ -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: GPL-3
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 @@ Library
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
diff --git a/src/Data/Complex/Cyclotomic.hs b/src/Data/Complex/Cyclotomic.hs
index 2eba160..581d23b 100644
--- a/src/Data/Complex/Cyclotomic.hs
+++ b/src/Data/Complex/Cyclotomic.hs
@@ -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 @@ Stability : experimental
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,8 +121,15 @@ import qualified Data.Map as M
, 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.
@@ -223,8 +230,8 @@ sqrtPositiveInteger :: Integer -> Cyclotomic
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 @@ tryRational c
(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 :: Cyclotomic -> Cyclotomic
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 2 q = concatMap (includeMods n q) $ map ((n `div` q) *) [q `div` 2.
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.