| 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 |
Data.Number.RealCyclotomic
Description
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
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
- 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
- goldenRatio :: RealCyclotomic
- heron :: Rational -> Rational -> Rational -> RealCyclotomic
Documentation
data RealCyclotomic #
A real cyclotomic number.
Instances
sqrtRat :: Rational -> RealCyclotomic #
The square root of a Rational number.
sinDeg :: Rational -> RealCyclotomic #
Sine function with argument in degrees.
cosDeg :: Rational -> RealCyclotomic #
Cosine function with argument in degrees.
sinRev :: Rational -> RealCyclotomic #
Sine function with argument in revolutions.
cosRev :: Rational -> RealCyclotomic #
Cosine function with argument in revolutions.
isRat :: RealCyclotomic -> Bool #
Is the cyclotomic a rational?
toRat :: RealCyclotomic -> Maybe Rational #
Return an exact rational number if possible.
toReal :: RealFloat a => RealCyclotomic -> a #
Export as an inexact real number.
goldenRatio :: RealCyclotomic #
The golden ratio, (1 + √5)/2.