Copyright | (c) Scott N. Walck 2012-2017 |
---|---|
License | GPL-3 (see LICENSE) |
Maintainer | Scott N. Walck <walck@lvc.edu> |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
The real cyclotomic numbers are a subset of the real numbers with the following properties:
- The real cyclotomic numbers are represented exactly, enabling exact computations and equality comparisons.
- The real cyclotomic numbers contain the rationals. As a consequence, the real cyclotomic numbers are a dense subset of the real numbers.
- The real cyclotomic numbers contain the square roots of all nonnegative rational numbers.
- The real cyclotomic numbers form a field: they are closed under addition, subtraction, multiplication, and division.
- 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
RealCyclotomic
s 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
- data RealCyclotomic
- sqrtRat :: Rational -> RealCyclotomic
- sinDeg :: Rational -> RealCyclotomic
- cosDeg :: Rational -> RealCyclotomic
- sinRev :: Rational -> RealCyclotomic
- cosRev :: Rational -> RealCyclotomic
- isRat :: RealCyclotomic -> Bool
- toRat :: RealCyclotomic -> Maybe Rational
- toReal :: RealFloat a => RealCyclotomic -> a
- magSq :: RealCyclotomic -> RealCyclotomic
- goldenRatio :: RealCyclotomic
- heron :: Rational -> Rational -> Rational -> RealCyclotomic
Documentation
data RealCyclotomic Source #
A real cyclotomic number.
Instances
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?
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
.