{-# LANGUAGE RebindableSyntax #-}
module MathObj.PowerSeries.Mean where
import qualified MathObj.PowerSeries2 as PS2
import qualified MathObj.PowerSeries2.Core as PS2Core
import qualified MathObj.PowerSeries as PS
import qualified MathObj.PowerSeries.Core as PSCore
import qualified MathObj.PowerSeries.Example as PSE
import qualified Algebra.Field as Field
import qualified Algebra.Ring as Ring
import Data.List.HT (shearTranspose)
import NumericPrelude.Numeric
import NumericPrelude.Base
diffComp :: (Ring.C a) => [a] -> [a] -> [a]
diffComp :: [a] -> [a] -> [a]
diffComp [a]
ys [a]
x =
([a] -> a) -> [[a]] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map [a] -> a
forall a. C a => [a] -> a
sum ([[a]] -> [[a]]
forall a. [[a]] -> [[a]]
shearTranspose ([[a]] -> [[a]]
forall a. [a] -> [a]
tail ((a -> [a] -> [a]) -> [a] -> [[a]] -> [[a]]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith a -> [a] -> [a]
forall a. C a => a -> [a] -> [a]
PSCore.scale [a]
ys
(([a] -> [a]) -> [[a]] -> [[a]]
forall a b. (a -> b) -> [a] -> [b]
map [a] -> [a]
forall a. [a] -> [a]
tail (([a] -> [a]) -> [a] -> [[a]]
forall a. (a -> a) -> a -> [a]
iterate ([a] -> [a] -> [a]
forall a. C a => [a] -> [a] -> [a]
PSCore.mul [a]
x) [a
1])))))
logarithmic :: (Field.C a) => [a]
logarithmic :: [a]
logarithmic =
let
fracLn :: [a]
fracLn = [a] -> [a] -> [a]
forall a. C a => [a] -> [a] -> [a]
PSCore.divide [a
2]
([a] -> [a]
forall a. [a] -> [a]
tail ((a -> a -> a) -> [a] -> [a] -> [a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith a -> a -> a
forall a. C a => a -> a -> a
(*) ((a -> a) -> a -> [a]
forall a. (a -> a) -> a -> [a]
iterate (a
2a -> a -> a
forall a. C a => a -> a -> a
*) a
1) [a]
forall a. C a => [a]
PSE.log))
fDiffFracLn :: [a]
fDiffFracLn = [a] -> [a] -> [a]
forall a. C a => [a] -> [a] -> [a]
diffComp [a]
f ([a] -> [a]
forall a. [a] -> [a]
tail [a]
fracLn)
f :: [a]
f = a
0 a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
1 a -> [a] -> [a]
forall a. a -> [a] -> [a]
: (a -> a -> a) -> [a] -> [a] -> [a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith a -> a -> a
forall a. C a => a -> a -> a
(/) [a]
fDiffFracLn
((a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (a -> a -> a
forall a. C a => a -> a -> a
subtract a
1) ((a -> a) -> a -> [a]
forall a. (a -> a) -> a -> [a]
iterate (a
2a -> a -> a
forall a. C a => a -> a -> a
*) a
2))
in [a]
f
elemSym3_2 :: (Field.C a) => [a]
elemSym3_2 :: [a]
elemSym3_2 =
let
root :: [a]
root = (a -> a -> a) -> [a] -> [a] -> [a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith a -> a -> a
forall a. C a => a -> a -> a
(*) ((a -> a) -> a -> [a]
forall a. (a -> a) -> a -> [a]
iterate (a
2a -> a -> a
forall a. C a => a -> a -> a
*) a
1) [a]
forall a. C a => [a]
PSE.sqrt
fDiffRoot :: [a]
fDiffRoot = [a] -> [a] -> [a]
forall a. C a => [a] -> [a] -> [a]
diffComp [a]
f ([a] -> [a]
forall a. [a] -> [a]
tail [a]
root)
f :: [a]
f = a
0 a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
1 a -> [a] -> [a]
forall a. a -> [a] -> [a]
: (a -> a -> a) -> [a] -> [a] -> [a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith a -> a -> a
forall a. C a => a -> a -> a
(/) [a]
fDiffRoot
((a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (a -> a -> a
forall a. C a => a -> a -> a
subtract a
1) ((a -> a) -> a -> [a]
forall a. (a -> a) -> a -> [a]
iterate (a
3a -> a -> a
forall a. C a => a -> a -> a
*) a
3))
in [a]
f
quadratic :: (Field.C a, Eq a) => [a]
quadratic :: [a]
quadratic = (a -> a) -> [a] -> [a]
forall a. C a => (a -> a) -> [a] -> [a]
PSCore.sqrt (\a
1 -> a
1) [a
1,a
1,a
1a -> a -> a
forall a. C a => a -> a -> a
/a
2]
quadraticMVF :: (Field.C a) => [a]
quadraticMVF :: [a]
quadraticMVF =
[a
1,a
1,a
1,a
1,a
1a -> a -> a
forall a. C a => a -> a -> a
/a
2,-a
1a -> a -> a
forall a. C a => a -> a -> a
/a
14]
quadraticDiff :: (Field.C a, Eq a) => [a]
quadraticDiff :: [a]
quadraticDiff =
let divDiffPS :: [a]
divDiffPS = [a] -> [a]
forall a. [a] -> [a]
tail [a]
forall a. C a => [a]
quadraticMVF
(a
1, [a]
invPS) = [a] -> (a, [a])
forall a. (Eq a, C a) => [a] -> (a, [a])
PSCore.inv ([a] -> [a]
forall a. C a => [a] -> [a]
PSCore.differentiate [a]
forall a. C a => [a]
quadraticMVF)
meanValuePS :: [a]
meanValuePS = (a -> [a]) -> [a] -> [a]
forall a. C a => (a -> [a]) -> [a] -> [a]
PSCore.composeTaylor (\a
1 -> [a]
invPS) [a]
divDiffPS
in [a]
forall a. (C a, Eq a) => [a]
quadratic [a] -> [a] -> [a]
forall a. C a => a -> a -> a
- [a]
meanValuePS
quadratic2 :: (Field.C a, Eq a) => PS2Core.T a
quadratic2 :: T a
quadratic2 =
(a -> a) -> T a -> T a
forall a. C a => (a -> a) -> T a -> T a
PS2Core.sqrt (\a
1 -> a
1) [[a
1],[a
1,a
1],[a
1a -> a -> a
forall a. C a => a -> a -> a
/a
2,a
0,a
1a -> a -> a
forall a. C a => a -> a -> a
/a
2]]
quadraticDiff2 :: (Field.C a, Eq a) => PS2Core.T a
quadraticDiff2 :: T a
quadraticDiff2 =
T a -> [a] -> T a
forall a. (C a, Eq a) => T a -> [a] -> T a
meanValueDiff2 T a
forall a. (C a, Eq a) => T a
quadratic2 [a]
forall a. C a => [a]
quadraticMVF
harmonicMVF :: (Field.C a) => [a]
harmonicMVF :: [a]
harmonicMVF =
[a
1,a
1,a
3,-a
6,a
21a -> a -> a
forall a. C a => a -> a -> a
/a
2,-a
186a -> a -> a
forall a. C a => a -> a -> a
/a
11]
harmonic2 :: (Field.C a, Eq a) => PS2Core.T a
harmonic2 :: T a
harmonic2 =
let rec :: T a
rec = [a] -> T a
forall a. [a] -> T a
PS.fromCoeffs [a]
forall a. C a => [a]
PSE.recip
in T a -> T a -> T a
forall a. C a => T a -> T a -> T a
PS2Core.divide [[a
2]] (T a -> T a) -> T a -> T a
forall a b. (a -> b) -> a -> b
$
T a -> T a
forall a. T a -> T a
PS2.coeffs (T a -> T a) -> T a -> T a
forall a b. (a -> b) -> a -> b
$
T a -> T a
forall a. C a => T a -> T a
PS2.fromPowerSeries0 T a
rec T a -> T a -> T a
forall a. C a => a -> a -> a
+
T a -> T a
forall a. C a => T a -> T a
PS2.fromPowerSeries1 T a
rec
harmonicDiff2 :: (Field.C a, Eq a) => PS2Core.T a
harmonicDiff2 :: T a
harmonicDiff2 =
T a -> [a] -> T a
forall a. (C a, Eq a) => T a -> [a] -> T a
meanValueDiff2 T a
forall a. (C a, Eq a) => T a
harmonic2 [a]
forall a. C a => [a]
harmonicMVF
arithmeticMVF :: (Field.C a) => [a]
arithmeticMVF :: [a]
arithmeticMVF = [a
1,a
2,a
1]
arithmetic2 :: (Field.C a, Eq a) => PS2Core.T a
arithmetic2 :: T a
arithmetic2 = [[a
1],[a
1a -> a -> a
forall a. C a => a -> a -> a
/a
2,a
1a -> a -> a
forall a. C a => a -> a -> a
/a
2]]
arithmeticDiff2 :: (Field.C a, Eq a) => PS2Core.T a
arithmeticDiff2 :: T a
arithmeticDiff2 =
T a -> [a] -> T a
forall a. (C a, Eq a) => T a -> [a] -> T a
meanValueDiff2 T a
forall a. (C a, Eq a) => T a
arithmetic2 [a]
forall a. C a => [a]
arithmeticMVF
geometricMVF :: (Field.C a) => [a]
geometricMVF :: [a]
geometricMVF = [a]
forall a. C a => [a]
PSE.recip
geometric2 :: (Field.C a, Eq a) => PS2Core.T a
geometric2 :: T a
geometric2 =
(a -> a) -> T a -> T a
forall a. C a => (a -> a) -> T a -> T a
PS2Core.sqrt (\a
1 -> a
1) [[a
1],[a
1,a
1],[a
0,a
1,a
0]]
geometricDiff2 :: (Field.C a, Eq a) => PS2Core.T a
geometricDiff2 :: T a
geometricDiff2 =
T a -> [a] -> T a
forall a. (C a, Eq a) => T a -> [a] -> T a
meanValueDiff2 T a
forall a. (C a, Eq a) => T a
geometric2 [a]
forall a. C a => [a]
geometricMVF
meanValueDiff2 :: (Field.C a, Eq a) =>
PS2Core.T a -> [a] -> PS2Core.T a
meanValueDiff2 :: T a -> [a] -> T a
meanValueDiff2 T a
mean2 [a]
curve =
let
divDiffPS :: T a
divDiffPS =
(Int -> a -> [a]) -> [Int] -> [a] -> T a
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Int -> a -> [a]
forall a. Int -> a -> [a]
replicate [Int
1..] ([a] -> T a) -> [a] -> T a
forall a b. (a -> b) -> a -> b
$ [a] -> [a]
forall a. [a] -> [a]
tail [a]
curve
meanValuePS :: T a
meanValuePS =
[a] -> T a -> T a
forall a. C a => [a] -> T a -> T a
PS2Core.compose ([a] -> [a]
forall a. C a => [a] -> [a]
PSCore.differentiate [a]
curve) (T a -> T a
forall a. [a] -> [a]
tail T a
mean2)
in T a
meanValuePS T a -> T a -> T a
forall a. C a => a -> a -> a
- T a
divDiffPS