-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Exact computation with constructible real numbers -- -- The constructible reals are the subset of the real numbers that can be -- represented exactly using field operations (addition, subtraction, -- multiplication, division) and positive square roots. They support -- exact computations, equality comparisons, and ordering. @package constructible @version 0.1.1 -- | The constructible reals, Construct, are the subset of the real -- numbers that can be represented exactly using field operations -- (addition, subtraction, multiplication, division) and positive square -- roots. They support exact computations, equality comparisons, and -- ordering. -- --
--   >>> [((1 + sqrt 5)/2)^n - ((1 - sqrt 5)/2)^n :: Construct | n <- [1..10]]
--   [sqrt 5,sqrt 5,2*sqrt 5,3*sqrt 5,5*sqrt 5,8*sqrt 5,13*sqrt 5,21*sqrt 5,34*sqrt 5,55*sqrt 5]
--   
-- --
--   >>> let f (a, b, t, p) = ((a + b)/2, sqrt (a*b), t - p*((a - b)/2)^2, 2*p)
--   
--   >>> let (a, b, t, p) = f . f . f . f $ (1, 1/sqrt 2, 1/4, 1 :: Construct)
--   
--   >>> floor $ ((a + b)^2/(4*t))*10**40
--   31415926535897932384626433832795028841971
--   
-- --
--   >>> let qf (p, q) = ((p + sqrt (p^2 - 4*q))/2, (p - sqrt (p^2 - 4*q))/2 :: Construct)
--   
--   >>> let [(v, w), (x, _), (y, _), (z, _)] = map qf [(-1, -4), (v, -1), (w, -1), (x, y)]
--   
--   >>> z/2
--   -1/16 + 1/16*sqrt 17 + 1/8*sqrt (17/2 - 1/2*sqrt 17) + 1/4*sqrt (17/4 + 3/4*sqrt 17 - (3/4 + 1/4*sqrt 17)*sqrt (17/2 - 1/2*sqrt 17))
--   
-- -- Constructible complex numbers may be built from constructible reals -- using Complex from the complex-generic library. -- --
--   >>> (z/2 :+ sqrt (1 - (z/2)^2))^17
--   1 :+ 0
--   
module Data.Real.Constructible -- | The type of constructible real numbers. data Construct -- | Deconstruct a rational constructible number as a Rational, or -- an irrational constructible number as a triple (a, b, r) of -- simpler constructible numbers representing a + b*sqrt r (with -- b /= 0 and r > 0). Recursively calling -- deconstruct on all triples will yield a finite tree that -- terminates in Rational leaves. -- -- Note that two constructible numbers that compare as equal may -- deconstruct in different ways. deconstruct :: Construct -> Either Rational (Construct, Construct, Construct) -- | Evaluate a floating-point approximation for a constructible number. -- -- To improve numerical stability, addition of numbers with different -- signs is avoided using quadratic conjugation. -- --
--   >>> fromConstruct $ sum (map sqrt [7, 14, 39, 70, 72, 76, 85]) - sum (map sqrt [13, 16, 46, 55, 67, 73, 79])
--   1.8837969820815017e-19
--   
fromConstruct :: Floating a => Construct -> a -- | The type of exceptions thrown by impossible Construct -- operations. data ConstructException -- | toRational was given an irrational constructible number. ConstructIrrational :: ConstructException -- | sqrt was given a negative constructible number. ConstructSqrtNegative :: ConstructException -- | ** was given an exponent that is not a dyadic rational, or a -- transcendental function was called. Unconstructible :: String -> ConstructException instance Data.Complex.Generic.Class.ComplexRect (Data.Complex.Generic.Complex Data.Real.Constructible.Construct) Data.Real.Constructible.Construct instance Data.Complex.Generic.Class.ComplexPolar (Data.Complex.Generic.Complex Data.Real.Constructible.Construct) Data.Real.Constructible.Construct instance GHC.Num.Num (Data.Complex.Generic.Complex Data.Real.Constructible.Construct) instance GHC.Real.Fractional (Data.Complex.Generic.Complex Data.Real.Constructible.Construct) instance GHC.Float.Floating (Data.Complex.Generic.Complex Data.Real.Constructible.Construct) instance GHC.Classes.Ord Data.Real.Constructible.ConstructException instance GHC.Classes.Eq Data.Real.Constructible.ConstructException instance GHC.Show.Show Data.Real.Constructible.FieldShape instance GHC.Show.Show Data.Real.Constructible.ConstructException instance GHC.Exception.Type.Exception Data.Real.Constructible.ConstructException instance GHC.Float.Floating Data.Real.Constructible.Construct instance GHC.Real.Real Data.Real.Constructible.Construct instance GHC.Classes.Eq Data.Real.Constructible.Construct instance GHC.Classes.Ord Data.Real.Constructible.Construct instance GHC.Num.Num Data.Real.Constructible.Construct instance GHC.Real.Fractional Data.Real.Constructible.Construct instance GHC.Show.Show Data.Real.Constructible.Construct instance GHC.Read.Read Data.Real.Constructible.Construct instance GHC.Real.RealFrac Data.Real.Constructible.Construct instance GHC.Enum.Enum Data.Real.Constructible.Construct instance GHC.Show.Show (Data.Real.Constructible.Field k)