Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- newtype R = Limit (Endo Rational)
- lim :: Stream R -> R
- real :: (Rational -> Rational) -> R
- approximate :: R -> Rational -> Rational
- rational_approximations :: Approximations str a => a -> str Rational
- average :: R -> R -> R
- floating_approximations :: Approximations str a => a -> str Double
- epsilon :: R
- infinite_r :: R
- liftR :: (Rational -> Rational) -> R -> R
- derivate_generic_stream :: Fractional a => (a -> a) -> Stream a -> Stream a
- liftR2 :: (Rational -> Rational -> Rational) -> R -> R -> R
- inverseImage :: (Rational -> Rational) -> R -> R
- liftWithAccuracy :: (Rational -> Rational) -> (Rational -> Rational) -> R -> R
- approximate_as :: R -> R -> R
- limit_compose :: (Rational -> R) -> R -> R
- inverseImageEndo :: Endo Rational -> Endo R
- differentialLiftR :: (Rational -> Rational) -> R -> R
- derivate_rational :: Rational -> (Rational -> Rational) -> Rational -> Rational
- derivate_r :: (R -> R) -> R -> R
- newtons_method_r :: (R -> R) -> R -> R
- sqrt_r :: R -> R
- log_by_newton :: R -> R
- exp_r :: R -> R
- pi_r :: R
- log_r :: R -> R
- integral_r :: (R, R) -> (R -> R) -> R
- foldable_integral :: (Foldable t, Functor t) => (Rational -> t b) -> (b -> R) -> R
- foldable_simple_integral :: (Num a, Foldable t, Functor t) => (a -> t b) -> (b -> a) -> a -> a
- integral_accuracy :: Fractional t => (t -> R) -> R -> R -> Rational -> [Rational]
- asin_r :: R -> R
- acos_r :: R -> R
- atan_r :: R -> R
- sin_by_series :: R -> R
- inverse_of_r :: (R -> R) -> R -> R
- cos_by_series :: R -> R
- gamma_r :: R -> R
- lub_r :: [R] -> Maybe R
- glb_r :: [R] -> Maybe R
- computable_r :: (Rational -> Rational -> Rational) -> R
- unsafe_real_to_rational :: R -> Rational
- floor_r :: Integral b => R -> b
- ceiling_r :: Integral b => R -> b
- round_r :: Integral b => R -> b
- truncate_r :: Integral b => R -> b
- properFraction_r :: Integral b => R -> (b, R)
- approximately_less_than_or_equal_r :: Rational -> R -> R -> Bool
- approximately_less_than_r :: Rational -> R -> R -> Bool
- approximately_greater_than_or_equal_r :: Rational -> R -> R -> Bool
- approximately_greater_than_r :: Rational -> R -> R -> Bool
- approximately_equal_to_r :: Rational -> R -> R -> Bool
- max_r :: R -> R -> R
- min_r :: R -> R -> R
- real_to_float :: R -> Float
- real_to_double :: R -> Double
- data Limited a where
- LimitedRationalsAbove :: (Rational -> Rational) -> NonEmpty Rational -> R -> Limited Rational
- LimitedRationalsBelow :: (Rational -> Rational) -> NonEmpty Rational -> R -> Limited Rational
- LimitedRationalsAboveBelow :: (Rational -> Rational) -> NonEmpty Rational -> NonEmpty Rational -> R -> R -> Limited Rational
- supremum :: Limited Rational -> Maybe R
- infinum :: Limited Rational -> Maybe R
- bounded_approximations :: Limited Rational -> Rational -> Rational
- upper_bounds :: Limited Rational -> [Rational]
- lower_bounds :: Limited Rational -> [Rational]
Documentation
This real representation takes epsilon
as input as in epsilon-delta proof.
Instances
approximate :: R -> Rational -> Rational Source #
approximate takes a real \(r\), and a rational \(q\) and produces a rational \(q_2\) such that \(|r - q_2| \le q\)
\(r_1 (r_2 q) = (r_1 r_2) q\), where \(r_1,r_2 \in {\mathbf{R}}\), \(q \in {\mathbf{Q}}\).
that is, \[{\mathbf{approximate}}(r_1) \circ {\mathbf{approximate}}(r_2) = {\mathbf{approximate}}(r_1 r_2)\] that is, \[{\mathbf{approximate}}(r_1,{\mathbf{approximate}}(r_2,q)) = {\mathbf{approximate}}(r_1 r_2, q)\] that is \[{\mathbf{approximate}}(r_1,q_3)=q_2 \Leftrightarrow |r_1 - q_2| \le q_3\] \[{\mathbf{approximate}}(r_2,q) =q_3 \Leftrightarrow |r_2 - q_3| \le q\] \[{\mathbf{approximate}}(r_1 r_2, q)=q_2 \Leftrightarrow |r_1 r_2 - q_2| \le q\] \[{\mathbf{approximate}}(r_1 r_2, q)={\mathbf{approximate}}(r_1,q_3)={\mathbf{approximate}}(r_1,{\mathbf{approximate}}(r_2,q))\] \[\Leftrightarrow |r_1 - q_2| \le q_3 \land |r_2 - q_3| \le q\]
rational_approximations :: Approximations str a => a -> str Rational Source #
floating_approximations :: Approximations str a => a -> str Double Source #
infinite_r :: R Source #
derivate_generic_stream :: Fractional a => (a -> a) -> Stream a -> Stream a Source #
liftR2 :: (Rational -> Rational -> Rational) -> R -> R -> R Source #
this propagates accuracy without changing it
inverseImage :: (Rational -> Rational) -> R -> R Source #
inverseImage transforms accuracy computation of the real.
liftWithAccuracy :: (Rational -> Rational) -> (Rational -> Rational) -> R -> R Source #
The first argument is the function lifted. The second argument describes change in accuracy by the function.
approximate_as :: R -> R -> R Source #
approx_compose will use the second real as the level of approximation to compute the first.
differentialLiftR :: (Rational -> Rational) -> R -> R Source #
This lifts a rational function to a real function. This computes accuracy using the formula \(dx = df / f'(x)\). The accuracy behaves badly when \(f'(x) = 0\) due to divide-by-zero.
derivate_rational :: Rational -> (Rational -> Rational) -> Rational -> Rational Source #
derivate for rational functions. The first argument is epsilon.
derivate_r :: (R -> R) -> R -> R Source #
computes derivate. \[{{df}\over{dt}} = \lim_{\epsilon\rightarrow 0}{{f(t+\epsilon)-f(t)}\over{\epsilon}}\]
newtons_method_r :: (R -> R) -> R -> R Source #
newton's method for finding root of function. \[x_{i+1} = x_i - {{f(x_i)}\over{f'(x_i)}}\]
square root of a real number \(x\), computed with newton's method as root of \(t \mapsto t^2 - x\).
log_by_newton :: R -> R Source #
logarithm of a real number \(x\), computed with newton's method as root of \(t \mapsto e^t - x\).
Using Simon Plouffe's BPP digit extraction algorithm for computing pi. See https://plouffe.fr/Simon%20Plouffe.htm See Pi for details. \[\pi = \sum_{k=0}^{\infty}{16^{-k}}({{4}\over{8k+1}}-{{2}\over{8k+4}}-{1\over{8k+5}}-{1\over{8k+6}})\]
foldable_simple_integral :: (Num a, Foldable t, Functor t) => (a -> t b) -> (b -> a) -> a -> a Source #
integral_accuracy :: Fractional t => (t -> R) -> R -> R -> Rational -> [Rational] Source #
sin_by_series :: R -> R Source #
trigonometric functions Computed using taylor series expansion of sin function. \[\sin(x) = \sum_{k=0}^{\infty}{{{(-1)^k}\over{(2k+1)!}}{x^{2k+1}}}\]
cos_by_series :: R -> R Source #
trigonometric functions Computed using taylor series expansion of cos function. \[\cos(x) = \sum_{k=0}^{\infty}{{{(-1)^k}\over{(2k)!}}{x^{2k}}}\]
computable_r :: (Rational -> Rational -> Rational) -> R Source #
For \(a,b \in {\mathbb Q}\) and \(0 \in (a,b) \) the invocation \(f(a)(b)\) of \(f\) in \(computable\_r(f)\) must produce approximation \(q\) of another real \(r\) as rational number, such that \( r - q \in (a,b) \).
unsafe_real_to_rational :: R -> Rational Source #
this real_to_rational operation sets precision \(\epsilon\) to 0 and produces corresponding rational number. Many algorithms for reals will go to infinite loop, if this is used, or produce divide-by-zero. In particular, this is expected for irrationals. if rational number is produced, it's exact. However, computations on rational numbers, where real number was created using fromRational, will produce that rational. It also allows operations lifted from rationals to work, producing the result you'd obtain from rational numbers.
truncate_r :: Integral b => R -> b Source #
real_to_float :: R -> Float Source #
real_to_double :: R -> Double Source #
LimitedRationalsAbove :: (Rational -> Rational) -> NonEmpty Rational -> R -> Limited Rational | |
LimitedRationalsBelow :: (Rational -> Rational) -> NonEmpty Rational -> R -> Limited Rational | |
LimitedRationalsAboveBelow :: (Rational -> Rational) -> NonEmpty Rational -> NonEmpty Rational -> R -> R -> Limited Rational |