{-# LANGUAGE RebindableSyntax #-}{- |
This module computes power series for
representing some means as generalized $f$-means.
-}moduleMathObj.PowerSeries.MeanwhereimportqualifiedMathObj.PowerSeries2asPS2importqualifiedMathObj.PowerSeries2.CoreasPS2CoreimportqualifiedMathObj.PowerSeriesasPSimportqualifiedMathObj.PowerSeries.CoreasPSCoreimportqualifiedMathObj.PowerSeries.ExampleasPSEimportqualifiedAlgebra.FieldasFieldimportqualifiedAlgebra.RingasRingimportData.List.HT(shearTranspose)importNumericPrelude.NumericimportNumericPrelude.Base{-
$M_f$ is a generalized $f$-mean (quasi-arithmetic) if
\[M_f x = f^{ -1}\right(\frac{1}{n}\cdot\sum_{k=1}^{n} f(x_k)\left)\]
For instance there is the logarithmic mean
defined by
\[\frac{x-y}{\ln x - \ln y}\]
whose definition is inherently bound to two variables.
If we find a representation as a generalized $f$-mean
we can generalize this mean to more than two variables.
Btw. we can easily see that the logarithmic mean is not a quasi-arithmetic mean,
because \[ \anonymfunc{(a,b,c,d)}{L(L(a,b),L(c,d))} \]
is not commutative, but quasi-arithmetic means are always commutative.
First we note that an arbitrary constant offset and
an arbitrary scaling of $f$ does not alter the mean.
Therefore we choose $f(1)=0, f'(1)=1$
and we expand $f$ into a Taylor series with respect to 1.
For the logarithmic mean we will choose $y=0$.
This way we might get additional virtual solutions,
but we can identify them afterwards by a test.
\begin{eqnarray*}
f^{ -1}\left(\frac{f(1+x)+f(1+y)}{2}\right)
&=& \frac{x-y}{\ln(1+x) - \ln(1+y)} \\
f^{ -1}\left(\frac{f(1+x)}{2}\right)
&=& \frac{x}{\ln(1+x)} \\
f(1+x)
&=& 2 \cdot f\left(\frac{x}{\ln(1+x)}\right)
\end{eqnarray*}
This cannot be solved immediately
because in the power series expansions on both sides
unknown coefficients occur at the same monomials.
We can resolve that by subtracting the series of $2\cdot f(1+x/2)$
off both sides.
\begin{eqnarray*}
f(1+x) - 2\cdot f(1+x/2)
&=& 2 \cdot (f\left(\frac{x}{\ln(1+x)}\right) - f(1+x/2))
\end{eqnarray*}
We note that $1+x/2$ is the truncated series of $\frac{x}{\ln(1+x)}$.
This is also necessary in order to obtain an equation.
Now we have to derive an implementation of the right-hand side.
This is a difference of two series compositions, namely
$f(x+a*x^2+b*x^3+\dots) - f(x)$ .
The implementation takes care that the vanishing terms are not computed
and thus allows solution of series fixed point equations.
It is just done by throwing away the leading terms of all powers
of the series $x+a*x^2+b*x^3+\dots$.
In $x$ the constant monomial is omitted,
in the result both the constant and the linear term are omitted.
-}diffComp::(Ring.Ca)=>[a]->[a]->[a]diffCompysx=mapsum(shearTranspose(tail(zipWithPSCore.scaleys(maptail(iterate(PSCore.mulx)[1]))))){-
Now we solve
\[
\frac{1}{2}\cdot f(1+2\cdot x) - f(1+x)
&=& f\left(\frac{2\cdot x}{\ln(1+2\cdot x)}\right) - f(1+x)
\]
-}logarithmic::(Field.Ca)=>[a]logarithmic=let-- series for \frac{2\cdot x}{\ln(1+2\cdot x)}fracLn=PSCore.divide[2](tail(zipWith(*)(iterate(2*)1)PSE.log))fDiffFracLn=diffCompf(tailfracLn)f=0:1:zipWith(/)fDiffFracLn(map(subtract1)(iterate(2*)2))infelemSym3_2::(Field.Ca)=>[a]elemSym3_2=let-- series for \frac{2\cdot x}{\ln(1+2\cdot x)}root=zipWith(*)(iterate(2*)1)PSE.sqrtfDiffRoot=diffCompf(tailroot)f=0:1:zipWith(/)fDiffRoot(map(subtract1)(iterate(3*)3))inf{-
Means constructed by mean value theorem.
\[ M(x,y) = f'^{ -1}((f(x)-f(y))/(x-y)) \]
\[ f(x) = x^2 \implies M - arithmetic mean \]
\[ f(x) = 1/x \implies M - geometric mean \]
Try to find a power series for $f$ for $M(x,y) = \sqrt{(x^2+y^2)/2}$
(quadratic mean).
Expansion point: 1.
$M(1+t,1) = \sqrt{1+t+t^2/2}$
-}quadratic::(Field.Ca,Eqa)=>[a]quadratic=PSCore.sqrt(\1->1)[1,1,1/2]quadraticMVF::(Field.Ca)=>[a]quadraticMVF=-- [1,1,1,1,1/2,3/23,2/143]-- [1,1,1,1,1/2,1/2][1,1,1,1,1/2,-1/14]-- map (\x -> PSCore.coeffs (meanValueDiff2 quadratic2 [1,1,1,1,1/2,x] !! 4) !! 2) (GNUPlot.linearScale 10 (-0.071429,-1/14::Double))-- take 20 $ Numerics.ZeroFinder.RegulaFalsi.zero (-1,0) (\x -> PSCore.coeffs (meanValueDiff2 quadratic2 [1::Double,1,1,1,1/2,x] !! 4) !! 2){-
Result: It seems,
that we cannot find an appropriate coefficient for the 5th power.
This indicates that it is not possible to represent
the quadratic mean as mean value mean.
-}quadraticDiff::(Field.Ca,Eqa)=>[a]quadraticDiff=letdivDiffPS=tailquadraticMVF-- (f(1+t)-f(1))/((1+t)-1)(1,invPS)=PSCore.inv(PSCore.differentiatequadraticMVF)meanValuePS=PSCore.composeTaylor(\1->invPS)divDiffPS{- instead of computing an inverse series
we could also apply (compose) the derived series
to the series of the quadratic mean. -}inquadratic-meanValuePS{-
Represent quadratic mean with a two-variate power series.
$M(1+x,1+y) = \sqrt{1+x+y+(x^2+y^2)/2}$
-}quadratic2::(Field.Ca,Eqa)=>PS2Core.Taquadratic2=PS2Core.sqrt(\1->1)[[1],[1,1],[1/2,0,1/2]]quadraticDiff2::(Field.Ca,Eqa)=>PS2Core.TaquadraticDiff2=meanValueDiff2quadratic2quadraticMVF{-
We can alter the square coefficient,
but consequently we have to scale the sub-sequent coefficients.
If the square coefficient is zero then the equation is fulfilled,
but this is a non-solution because it is degenerate.
-}harmonicMVF::(Field.Ca)=>[a]harmonicMVF=-- [1,1,1,-2,7/2,-62/11]-- [1,1,2,-4,7,-124/11][1,1,3,-6,21/2,-186/11]{-
$M(1+x,1+y) = 2/(recip (1+x) + recip (1+y))$
-}harmonic2::(Field.Ca,Eqa)=>PS2Core.Taharmonic2=letrec=PS.fromCoeffsPSE.recipinPS2Core.divide[[2]]$PS2.coeffs$PS2.fromPowerSeries0rec+PS2.fromPowerSeries1recharmonicDiff2::(Field.Ca,Eqa)=>PS2Core.TaharmonicDiff2=meanValueDiff2harmonic2harmonicMVFarithmeticMVF::(Field.Ca)=>[a]arithmeticMVF=[1,2,1]{-
$M(1+x,1+y) = 1+x/2+y/2$
-}arithmetic2::(Field.Ca,Eqa)=>PS2Core.Taarithmetic2=[[1],[1/2,1/2]]arithmeticDiff2::(Field.Ca,Eqa)=>PS2Core.TaarithmeticDiff2=meanValueDiff2arithmetic2arithmeticMVFgeometricMVF::(Field.Ca)=>[a]geometricMVF=PSE.recip{-
$M(1+x,1+y) = \sqrt{(1+x)·(1+y)}$
-}geometric2::(Field.Ca,Eqa)=>PS2Core.Tageometric2=PS2Core.sqrt(\1->1)[[1],[1,1],[0,1,0]]geometricDiff2::(Field.Ca,Eqa)=>PS2Core.TageometricDiff2=meanValueDiff2geometric2geometricMVFmeanValueDiff2::(Field.Ca,Eqa)=>PS2Core.Ta->[a]->PS2Core.TameanValueDiff2mean2curve=let-- (f(1+x)-f(1+y)) / (x-y)divDiffPS=zipWithreplicate[1..]$tailcurvemeanValuePS=PS2Core.compose(PSCore.differentiatecurve)(tailmean2)inmeanValuePS-divDiffPS