Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -0,0 +1,17 @@
import Data.Ratio ((%), numerator)
infixl 7 *.
(*.) :: Num a => a -> [a] -> [a]
x *. (p:ps) = x*p : x*.ps
instance Num a => Num [a] where
negate = map negate
(+) = zipWith (+)
(*) (p:ps) (q:qs) = p*q : ((p*.qs) + ps*(q:qs))
fromInteger n = fromInteger n:repeat 0
instance (Eq a, Fractional a) => Fractional [a] where
(/) (0:ps) (0:qs) = ps/qs
(/) (p:ps) (q:qs) = let r=p/q in r : (ps - r*.qs)/(q:qs)
fromRational q = fromRational q:repeat 0

View file

@ -0,0 +1,2 @@
expseq :: [Rational] -> [Rational]
expseq ps = zipWith (\p q -> p*fromInteger q) ps (scanl (*) 1 [1..])

View file

@ -0,0 +1,3 @@
infixr 9 |>
(|>) :: (Eq a, Num a) => [a] -> [a] -> [a]
(p:ps) |> (0:qs) = p : qs*(ps |> (0:qs))

View file

@ -0,0 +1,11 @@
exp1 :: [Rational]
exp1 = 0 : map (1%) factorials
where
factorials = scanl (*) 1 [2..]
exps :: [Rational]
exps = 1 : zipWith (*) exps [ 1%n | n <- [1..] ]
bell :: [Integer]
bell = map numerator
(expseq (exps |> exp1))

View file

@ -0,0 +1,4 @@
ghci> take 15 bell
[1,1,2,5,15,52,203,877,4140,21147,115975,678570,4213597,27644437,190899322]
ghci> bell !! 49
10726137154573358400342215518590002633917247281