{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_HADDOCK hide #-}
module Math.NumberTheory.Zeta.Dirichlet
( betas
, betasEven
, betasOdd
) where
import Data.ExactPi
import Data.List (zipWith4)
import Data.Ratio ((%))
import Math.NumberTheory.Recurrences (euler, factorial)
import Math.NumberTheory.Zeta.Hurwitz (zetaHurwitz)
import Math.NumberTheory.Zeta.Utils (intertwine, skipOdds)
betasOdd :: [ExactPi]
betasOdd = zipWith Exact [1, 3 ..] $ zipWith4
(\sgn denom eul twos -> sgn * (eul % (twos * denom)))
(cycle [1, -1])
(skipOdds factorial)
(skipOdds euler)
(iterate (4 *) 4)
betasEven :: forall a. (Floating a, Ord a) => a -> [a]
betasEven eps = (1 / 2) : hurwitz
where
hurwitz :: [a]
hurwitz =
zipWith3 (\quarter threeQuarters four ->
(quarter - threeQuarters) / four)
(tail . skipOdds $ zetaHurwitz eps 0.25)
(tail . skipOdds $ zetaHurwitz eps 0.75)
(iterate (16 *) 16)
betas :: (Floating a, Ord a) => a -> [a]
betas eps = e : o : scanl1 f (intertwine es os)
where
e : es = betasEven eps
o : os = map (getRationalLimit (\a b -> abs (a - b) < eps) . rationalApproximations) betasOdd
f x y = 1 `min` (y `max` (1 + (x - 1) / 2))