module Data.Number.ER.Real.Arithmetic.Taylor where
import qualified Data.Number.ER.Real.Approx as RA
import qualified Data.Number.ER.ExtendedInteger as EI
import Data.Number.ER.BasicTypes
erTaylor_R
:: (RA.ERIntApprox ira)
=> EffortIndex
-> (Int -> ira)
-> (Int -> ira)
-> ira
-> ira
-> ira
erTaylor_R ix coefSeq derivBounds a x =
erTaylor_R_FullArgs coefSeq derivBounds n a gran x
where
n = fromInteger ix
gran = fromInteger $ toInteger $ ix
erTaylor_R_FullArgs
:: (RA.ERIntApprox ira)
=> (Int -> ira)
-> (Int -> ira)
-> Int
-> ira
-> Granularity
-> ira
-> ira
erTaylor_R_FullArgs coefSeq derivBounds n a gran x =
rec_apTaylor (RA.setMinGranularity gran 0) 0
where
rec_apTaylor i j
| n > j = (coefSeq(j)) +
((x a)/(i+1)) * (rec_apTaylor (i+1) (j+1))
| n == j = derivBounds n
| otherwise =
error "Data.Number.ER.Real.Arithmetic.Taylor.hs: erTaylor_RA_FullArgs: The index n cannot be negative"
erExp_Tay_Opt_R
:: (RA.ERIntApprox ira)
=> EffortIndex
-> ira
-> ira
erExp_Tay_Opt_R ix x
| RA.isEmpty x = RA.emptyApprox
| x `RA.refines` (1/0) = 0
| otherwise = 1 + (te ix x (RA.setMinGranularity gran 1))
where
gran = effIx2gran ix
te steps x i
| steps > 0 =
(x/i) * (1 + (te (steps 1) x (i + 1)))
| steps == 0 =
errorBound
where
errorBound =
(x/i) * ithDerivBound
ithDerivBound
| xCeiling == EI.MinusInfinity =
0
| xCeiling < 0 =
pow26xFloor RA.\/ 1
| xFloor > 0 =
1 RA.\/ pow28xCeiling
| otherwise =
pow26xFloor RA.\/ pow28xCeiling
where
(xFloor, xCeiling) = RA.integerBounds x
pow26xFloor
| xFloor == EI.MinusInfinity =
0
| otherwise =
((RA.setMinGranularity gran 26)/10) ^^ xFloor
pow28xCeiling
| xCeiling == EI.PlusInfinity =
(1/0)
| otherwise =
((RA.setMinGranularity gran 28)/10) ^^ xCeiling
erSine_Tay_Opt_R
:: (RA.ERIntApprox ira)
=> EffortIndex
-> ira
-> ira
erSine_Tay_Opt_R ix x = taylor_seg ix x (RA.setMinGranularity gran 1)
where
gran = effIx2gran ix
taylor_seg i x n
| i > 0 = x ((x*x)/((n+1)*(n+2))) * (taylor_seg (i2) x (n+2))
| otherwise = errorRegion
where
errorRegion = (1) RA.\/ (1)
erCosine_Tay_Opt_R
:: (RA.ERIntApprox ira)
=> EffortIndex
-> ira
-> ira
erCosine_Tay_Opt_R ix x = taylor_seg ix x (RA.setMinGranularity gran 1)
where
gran = effIx2gran ix
taylor_seg i x n
| i > 0 = 1 ((x*x)/(n*(n+1))) * (taylor_seg (i2) x (n+2))
| otherwise = errorRegion
where
errorRegion = (1) RA.\/ (1)
--logTayCoefs
--logTay_RA