cyclotomic-0.1: A subfield of the complex numbers for exact calculation

Safe HaskellSafe-Infered

Data.Complex.Cyclotomic

Description

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 nth roots of unity for arbitrarily large integers n.

This algorithm for cyclotomic numbers is adapted from code by Martin Schoenert and Thomas Breuer in the GAP project http://www.gap-system.org/ . See in particular source files gap4r4/src/cyclotom.c and gap4r4/lib/cyclotom.gi .

Synopsis

Documentation

i :: CyclotomicSource

The square root of -1.

e :: Integer -> CyclotomicSource

The primitive nth root of unity. For example, e(4) = i is the primitive 4th root of unity, and e(5) = exp(2*pi*i/5) is the primitive 5th root of unity. In general, e n = exp(2*pi*i/n).

sqrtInteger :: Integer -> CyclotomicSource

The square root of an Integer.

sqrtRat :: Rational -> CyclotomicSource

The square root of a Rational number.

sinDeg :: Rational -> CyclotomicSource

Sine function with argument in degrees.

cosDeg :: Rational -> CyclotomicSource

Cosine function with argument in degrees.

conj :: Cyclotomic -> CyclotomicSource

Complex conjugate.

real :: Cyclotomic -> CyclotomicSource

Real part of the cyclotomic number.

imag :: Cyclotomic -> CyclotomicSource

Imaginary part of the cyclotomic number.

modSq :: Cyclotomic -> RationalSource

Modulus squared.

toComplex :: Cyclotomic -> Complex DoubleSource

Export as an inexact complex number.

isReal :: Cyclotomic -> BoolSource

Is the cyclotomic a real number?

isRational :: Cyclotomic -> BoolSource

Is the cyclotomic a rational?

isGaussianRational :: Cyclotomic -> BoolSource

Is the cyclotomic a Gaussian rational?

toRat :: Cyclotomic -> Maybe RationalSource

Return Just rational if the cyclotomic is rational, Nothing otherwise.