| Copyright | (c) Scott N. Walck 2012-2017 |
|---|---|
| License | GPL-3 (see LICENSE) |
| Maintainer | Scott N. Walck <walck@lvc.edu> |
| Stability | experimental |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Data.Complex.Cyclotomic
Description
The cyclotomic numbers are a subset of the complex numbers with the following properties:
- The cyclotomic numbers are represented exactly, enabling exact computations and equality comparisons.
- The cyclotomic numbers contain the Gaussian rationals
(complex numbers of the form
p+qiwithpandqrational). As a consequence, the cyclotomic numbers are a dense subset of the complex numbers. - The cyclotomic numbers contain the square roots of all rational numbers.
- The cyclotomic numbers form a field: they are closed under addition, subtraction, multiplication, and division.
- The cyclotomic numbers contain the sine and cosine of all rational multiples of pi.
- The cyclotomic numbers can be thought of as the rational field extended
with
nth roots of unity for arbitrarily large integersn.
Floating point numbers do not do well with equality comparison:
(sqrt 2 + sqrt 3)^2 == 5 + 2 * sqrt 6 -> False
Data.Complex.Cyclotomic represents these numbers exactly, allowing equality comparison:
(sqrtRat 2 + sqrtRat 3)^2 == 5 + 2 * sqrtRat 6 -> True
Cyclotomics can be exported as inexact complex numbers using the toComplex function:
e 6 -> -e(3)^2 real $ e 6 -> 1/2 imag $ e 6 -> -1/2*e(12)^7 + 1/2*e(12)^11 imag (e 6) == sqrtRat 3 / 2 -> True toComplex $ e 6 -> 0.5000000000000003 :+ 0.8660254037844384
The algorithms for cyclotomic numbers are adapted from code by Martin Schoenert and Thomas Breuer in the GAP project http://www.gap-system.org/ (in particular source files gap4r4/src/cyclotom.c and gap4r4/lib/cyclotom.gi).
Synopsis
- data Cyclotomic
- i :: Cyclotomic
- e :: Integer -> Cyclotomic
- sqrtInteger :: Integer -> Cyclotomic
- sqrtRat :: Rational -> Cyclotomic
- sinDeg :: Rational -> Cyclotomic
- cosDeg :: Rational -> Cyclotomic
- sinRev :: Rational -> Cyclotomic
- cosRev :: Rational -> Cyclotomic
- gaussianRat :: Rational -> Rational -> Cyclotomic
- polarRat :: Rational -> Rational -> Cyclotomic
- polarRatDeg :: Rational -> Rational -> Cyclotomic
- polarRatRev :: Rational -> Rational -> Cyclotomic
- conj :: Cyclotomic -> Cyclotomic
- real :: Cyclotomic -> Cyclotomic
- imag :: Cyclotomic -> Cyclotomic
- isReal :: Cyclotomic -> Bool
- isRat :: Cyclotomic -> Bool
- isGaussianRat :: Cyclotomic -> Bool
- toComplex :: RealFloat a => Cyclotomic -> Complex a
- toReal :: RealFloat a => Cyclotomic -> Maybe a
- toRat :: Cyclotomic -> Maybe Rational
- goldenRatio :: Cyclotomic
- dft :: [Cyclotomic] -> [Cyclotomic]
- dftInv :: [Cyclotomic] -> [Cyclotomic]
- rootsQuadEq :: Rational -> Rational -> Rational -> Maybe (Cyclotomic, Cyclotomic)
- heron :: Rational -> Rational -> Rational -> Cyclotomic
Documentation
data Cyclotomic #
A cyclotomic number.
Instances
| Eq Cyclotomic # | |
Defined in Data.Complex.Cyclotomic | |
| Fractional Cyclotomic # | |
Defined in Data.Complex.Cyclotomic Methods (/) :: Cyclotomic -> Cyclotomic -> Cyclotomic # recip :: Cyclotomic -> Cyclotomic # fromRational :: Rational -> Cyclotomic # | |
| Num Cyclotomic # |
|
Defined in Data.Complex.Cyclotomic Methods (+) :: Cyclotomic -> Cyclotomic -> Cyclotomic # (-) :: Cyclotomic -> Cyclotomic -> Cyclotomic # (*) :: Cyclotomic -> Cyclotomic -> Cyclotomic # negate :: Cyclotomic -> Cyclotomic # abs :: Cyclotomic -> Cyclotomic # signum :: Cyclotomic -> Cyclotomic # fromInteger :: Integer -> Cyclotomic # | |
| Show Cyclotomic # | |
Defined in Data.Complex.Cyclotomic Methods showsPrec :: Int -> Cyclotomic -> ShowS # show :: Cyclotomic -> String # showList :: [Cyclotomic] -> ShowS # | |
i :: Cyclotomic #
The square root of -1.
e :: Integer -> Cyclotomic #
sqrtInteger :: Integer -> Cyclotomic #
The square root of an Integer.
sqrtRat :: Rational -> Cyclotomic #
The square root of a Rational number.
sinDeg :: Rational -> Cyclotomic #
Sine function with argument in degrees.
cosDeg :: Rational -> Cyclotomic #
Cosine function with argument in degrees.
sinRev :: Rational -> Cyclotomic #
Sine function with argument in revolutions.
cosRev :: Rational -> Cyclotomic #
Cosine function with argument in revolutions.
gaussianRat :: Rational -> Rational -> Cyclotomic #
Make a Gaussian rational; gaussianRat p q is the same as p + q * i.
Arguments
| :: Rational | magnitude |
| -> Rational | angle, in revolutions |
| -> Cyclotomic | cyclotomic number |
A complex number in polar form, with rational magnitude r and rational angle s
of the form r * exp(2*pi*i*s); polarRat r s is the same as r * e q ^ p,
where s = p/q. This function is the same as polarRatRev.
Arguments
| :: Rational | magnitude |
| -> Rational | angle, in degrees |
| -> Cyclotomic | cyclotomic number |
A complex number in polar form, with rational magnitude and rational angle in degrees.
Arguments
| :: Rational | magnitude |
| -> Rational | angle, in revolutions |
| -> Cyclotomic | cyclotomic number |
A complex number in polar form, with rational magnitude and rational angle in revolutions.
conj :: Cyclotomic -> Cyclotomic #
Complex conjugate.
real :: Cyclotomic -> Cyclotomic #
Real part of the cyclotomic number.
imag :: Cyclotomic -> Cyclotomic #
Imaginary part of the cyclotomic number.
isReal :: Cyclotomic -> Bool #
Is the cyclotomic a real number?
isRat :: Cyclotomic -> Bool #
Is the cyclotomic a rational?
isGaussianRat :: Cyclotomic -> Bool #
Is the cyclotomic a Gaussian rational?
toComplex :: RealFloat a => Cyclotomic -> Complex a #
Export as an inexact complex number.
toReal :: RealFloat a => Cyclotomic -> Maybe a #
Export as an inexact real number if possible.
toRat :: Cyclotomic -> Maybe Rational #
Return an exact rational number if possible.
The golden ratio, (1 + √5)/2.
dft :: [Cyclotomic] -> [Cyclotomic] #
Discrete Fourier transform,
X_k = sum_{n=0}^{N-1} x_n cdot e^{-i 2 pi frac{k}{N} n}.
dftInv :: [Cyclotomic] -> [Cyclotomic] #
Inverse discrete Fourier transform,
x_n = frac{1}{N} sum_{k=0}^{N-1} X_k cdot e^{i 2 pi frac{k}{N} n}.
Arguments
| :: Rational | a |
| -> Rational | b |
| -> Rational | c |
| -> Maybe (Cyclotomic, Cyclotomic) | roots |
Solutions to the quadratic equation
a x^2 + b x + c = 0.
Returns Nothing if a == 0.