Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,9 @@
import Data.List
mmult :: Num a => [[a]] -> [[a]] -> [[a]]
mmult a b = [ [ sum $ zipWith (*) ar bc | bc <- (transpose b) ] | ar <- a ]
-- Example use:
test = [[1, 2],
[3, 4]] `mmult` [[-3, -8, 3],
[-2, 1, 4]]

View file

@ -0,0 +1,13 @@
import Data.Array
mmult :: (Ix i, Num a) => Array (i,i) a -> Array (i,i) a -> Array (i,i) a
mmult x y
| x1 /= y0 || x1' /= y0' = error "range mismatch"
| otherwise = array ((x0,y1),(x0',y1')) l
where
((x0,x1),(x0',x1')) = bounds x
((y0,y1),(y0',y1')) = bounds y
ir = range (x0,x0')
jr = range (y1,y1')
kr = range (x1,x1')
l = [((i,j), sum [x!(i,k) * y!(k,j) | k <- kr]) | i <- ir, j <- jr]

View file

@ -0,0 +1,18 @@
multiply :: Num a => [[a]] -> [[a]] -> [[a]]
multiply us vs = map (mult [] vs) us
where
mult xs [] _ = xs
mult xs _ [] = xs
mult [] (zs : zss) (y : ys) = mult (map (y *) zs) zss ys
mult xs (zs : zss) (y : ys) =
mult
(zipWith (\u v -> u + v * y) xs zs)
zss
ys
main :: IO ()
main =
mapM_ print $
multiply
[[1, 2], [3, 4]]
[[-3, -8, 3], [-2, 1, 4]]

View file

@ -0,0 +1,11 @@
mult :: Num a => [[a]] -> [[a]] -> [[a]]
mult uss vss =
let go xs
| null xs = []
| otherwise = foldl1 (zipWith (+)) xs
in go . zipWith (flip (map . (*))) vss <$> uss
main :: IO ()
main =
mapM_ print $
mult [[1, 2], [3, 4]] [[-3, -8, 3], [-2, 1, 4]]

View file

@ -0,0 +1,9 @@
import Numeric.LinearAlgebra
a, b :: Matrix I
a = (2 >< 2) [1, 2, 3, 4]
b = (2 >< 3) [-3, -8, 3, -2, 1, 4]
main :: IO ()
main = print $ a <> b