Matrix multiplication: Difference between revisions
→{{header|AppleScript}}: Slight reordering of functions
(→{{header|AppleScript}}: Simpler nesting of closures) |
(→{{header|AppleScript}}: Slight reordering of functions) |
||
Line 387:
end matrixMultiply
-- dotProduct :: [n] -> [n] -> Maybe n▼
on dotProduct(xs, ys)▼
script product▼
on lambda(a, b)▼
a * b▼
end lambda▼
end script▼
if length of xs is not length of ys then▼
missing value▼
else▼
sum(zipWith(product, xs, ys))▼
end if▼
end dotProduct▼
Line 421 ⟶ 407:
▲-- dotProduct :: [n] -> [n] -> Maybe n
▲on dotProduct(xs, ys)
-- GENERIC LIBRARY FUNCTIONS▼
▲ script product
▲ a * b
on add(a, b)▼
end
▲ if length of xs is not length of ys then
-- sum :: [n] -> n▼
▲ missing value
▲ else
reduce(add, 0, xs)▼
▲ sum(zipWith(product, xs, ys))
end sum▼
▲ end if
▲end dotProduct
-- transpose :: [[a]] -> [[a]]
Line 450 ⟶ 438:
map(column, item 1 of xss)
end transpose
▲-- sum :: [n] -> n
script add
▲ on lambda(a, b)
a + b
▲ end lambda
▲ end script
▲ reduce(add, 0, xs)
▲end sum
▲-- GENERIC LIBRARY FUNCTIONS
-- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
Line 497 ⟶ 501:
end script
end if
end mReturn
</lang>
{{Out}}
|