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
qrational). 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
nth roots of unity for arbitrarily large integers
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
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).
- data Cyclotomic
- i :: Cyclotomic
- e :: Integer -> Cyclotomic
- sqrtInteger :: Integer -> Cyclotomic
- sqrtRat :: Rational -> Cyclotomic
- sinDeg :: Rational -> Cyclotomic
- cosDeg :: Rational -> Cyclotomic
- gaussianRat :: Rational -> Rational -> Cyclotomic
- polarRat :: Rational -> Rational -> Cyclotomic
- conj :: Cyclotomic -> Cyclotomic
- real :: Cyclotomic -> Cyclotomic
- imag :: Cyclotomic -> Cyclotomic
- isReal :: Cyclotomic -> Bool
- isRat :: Cyclotomic -> Bool
- isGaussianRat :: Cyclotomic -> Bool
- toComplex :: Cyclotomic -> Complex Double
- toReal :: Cyclotomic -> Maybe Double
- toRat :: Cyclotomic -> Maybe Rational
A cyclotomic number.
Make a Gaussian rational;
gaussianRat p q is the same as
p + q * i.
A complex number in polar form, with rational magnitude
r and rational angle
of the form
r * exp(2*pi*i*s);
polarRat r s is the same as
r * e q ^ p,
s = p/q.