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

Copyright(c) Scott N. Walck 2012-2017
LicenseGPL-3 (see LICENSE)
MaintainerScott N. Walck <walck@lvc.edu>
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

Data.Number.RealCyclotomic

Description

The real cyclotomic numbers are a subset of the real numbers with the following properties:

  1. The real cyclotomic numbers are represented exactly, enabling exact computations and equality comparisons.
  2. The real cyclotomic numbers contain the rationals. As a consequence, the real cyclotomic numbers are a dense subset of the real numbers.
  3. The real cyclotomic numbers contain the square roots of all nonnegative rational numbers.
  4. The real cyclotomic numbers form a field: they are closed under addition, subtraction, multiplication, and division.
  5. The real cyclotomic numbers contain the sine and cosine of all rational multiples of pi (equivalently, the sine and cosine of any rational number of degrees or any rational number of revolutions).

Floating point numbers do not do well with equality comparison:

(sqrt 2 + sqrt 3)^2 == 5 + 2 * sqrt 6
 -> False

Data.Number.RealCyclotomic represents these numbers exactly, allowing equality comparison:

(sqrtRat 2 + sqrtRat 3)^2 == 5 + 2 * sqrtRat 6
 -> True

RealCyclotomics can be exported as inexact real numbers using the toReal function:

sqrtRat 2
 -> e(8) - e(8)^3
toReal $ sqrtRat 2
 -> 1.414213562373095

This module is based on the module Cyclotomic. Usually you would only import one of the modules RealCyclotomic or Cyclotomic, depending on whether you wanted only real numbers (this module) or complex numbers (the other). Functions such as sqrtRat, sinDeg, cosDeg are defined in both modules, with different type signatures, so their names will conflict if both modules are imported.

Synopsis

Documentation

sqrtRat :: Rational -> RealCyclotomic Source #

The square root of a Rational number.

sinDeg :: Rational -> RealCyclotomic Source #

Sine function with argument in degrees.

cosDeg :: Rational -> RealCyclotomic Source #

Cosine function with argument in degrees.

sinRev :: Rational -> RealCyclotomic Source #

Sine function with argument in revolutions.

cosRev :: Rational -> RealCyclotomic Source #

Cosine function with argument in revolutions.

isRat :: RealCyclotomic -> Bool Source #

Is the cyclotomic a rational?

toRat :: RealCyclotomic -> Maybe Rational Source #

Return an exact rational number if possible.

toReal :: RealFloat a => RealCyclotomic -> a Source #

Export as an inexact real number.

magSq :: RealCyclotomic -> RealCyclotomic Source #

The square of the magnitude of a real cyclotomic.

goldenRatio :: RealCyclotomic Source #

The golden ratio, (1 + √5)/2.

heron Source #

Arguments

:: Rational

a

-> Rational

b

-> Rational

c

-> RealCyclotomic

area of triangle

Heron's formula for the area of a triangle with side lengths a, b, c.