Matrix multiplication: Difference between revisions
→{{header|Raku}}: add an other take
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(→{{header|Raku}}: add an other take) |
||
Line 5,328:
Which overloads the built-in <code>×</code> operator for <code>Positional</code> operands. You’ll notice we are using <code>×</code> inside of the definition; since the arguments there are <code>Scalar</code>, it multiplies two numbers. Also, <code>do</code> is an alternative to parenthesising the loop for getting its result.
{{works with|Rakudo|2022.07-3}}
Here is an even more concise version, expressing the product of two matrices as the cross dot product of the first matrix with the transpose of the second :
<syntaxhighlight lang="raku" line>sub infix:<×>(@A, @B) {
cross(@A, ([Z] @B), with => { [+] @^a Z* @^b })
.rotor(@B);
}</syntaxhighlight>
=={{header|Rascal}}==
|