Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
|
|
@ -1,26 +1,10 @@
|
|||
foldlZipWith::(a -> b -> c) -> (d -> c -> d) -> d -> [a] -> [b] -> d
|
||||
foldlZipWith _ _ u [] _ = u
|
||||
foldlZipWith _ _ u _ [] = u
|
||||
foldlZipWith f g u (x:xs) (y:ys) = foldlZipWith f g (g u (f x y)) xs ys
|
||||
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
|
||||
|
||||
foldl1ZipWith::(a -> b -> c) -> (c -> c -> c) -> [a] -> [b] -> c
|
||||
foldl1ZipWith _ _ [] _ = error "First list is empty"
|
||||
foldl1ZipWith _ _ _ [] = error "Second list is empty"
|
||||
foldl1ZipWith f g (x:xs) (y:ys) = foldlZipWith f g (f x y) xs ys
|
||||
|
||||
multAdd::(a -> b -> c) -> (c -> c -> c) -> [[a]] -> [[b]] -> [[c]]
|
||||
multAdd f g xs ys = map (\us -> foldl1ZipWith (\u vs -> map (f u) vs) (zipWith g) us ys) xs
|
||||
|
||||
mult:: Num a => [[a]] -> [[a]] -> [[a]]
|
||||
mult xs ys = multAdd (*) (+) xs ys
|
||||
|
||||
test a b = do
|
||||
let c = mult a b
|
||||
putStrLn "a ="
|
||||
mapM_ print a
|
||||
putStrLn "b ="
|
||||
mapM_ print b
|
||||
putStrLn "c = a * b = mult a b ="
|
||||
mapM_ print c
|
||||
|
||||
main = test [[1, 2],[3, 4]] [[-3, -8, 3],[-2, 1, 4]]
|
||||
main :: IO ()
|
||||
main = mapM_ print $ multiply [[1, 2], [3, 4]] [[-3, -8, 3], [-2, 1, 4]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
mult :: Num a => [[a]] -> [[a]] -> [[a]]
|
||||
mult uss vss =
|
||||
map
|
||||
((\xs ->
|
||||
if null xs
|
||||
then []
|
||||
else foldl1 (zipWith (+)) xs) .
|
||||
zipWith (flip (map . (*))) vss)
|
||||
uss
|
||||
|
||||
main :: IO ()
|
||||
main = mapM_ print $ mult [[1, 2], [3, 4]] [[-3, -8, 3], [-2, 1, 4]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue