Jump to content

Cramer's rule: Difference between revisions

(Ada version)
Line 987:
insertEv x [] = [[x]]
insertEv x l@(y:ys) = (x:l) : map (y:) (insertEv x ys)
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
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 uss vss = map (foldl (zipWith (+)) ts . zipWith (\vs u -> map (u*) vs) vss) uss
mult xs ys = multAdd (*) (+) xs ys
where ts = map (const 0).concat $ take 1 vss
elemPos::[[a]] -> Int -> Int -> a
Line 1,126 ⟶ 1,114:
True
</pre>
 
===Version 3===
<lang Haskell>
678

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.