RosettaCodeData/Task/Matrix-multiplication/Lambdatalk/matrix-multiplication.lambdatalk
2020-02-17 23:21:07 -08:00

23 lines
877 B
Text

{def mat*mat
{lambda {:a :b}
{#.new {map {{lambda {:a :b :i} // loop on row
{#.new {map {{lambda {:a :b :i :j} // loop on col
{+ {map {{lambda {:a :b :i :j :k} // sum of prod
{* {#.get {#.get :a :i} :k} // of a[i,k]
{#.get {#.get :b :k} :j}} // and b[k,j]
} :a :b :i :j} {serie 0 {- {#.length :b} 1}} }}
} :a :b :i} {serie 0 {- {#.length {#.get :b 0}} 1}} }}
} :a :b} {serie 0 {- {#.length :a} 1}} }
}}}
{def A {#.new {#.new 1 2}
{#.new 3 4}
{#.new 5 6}
{#.new 7 8}}} = [[1,2],[3,4],[5,6],[7,8]]
{def B {#.new {#.new 1 2 3}
{#.new 4 5 6}}} = [[1,2,3],[4,5,6]]
{mat*mat {A} {B}}
-> [[ 9,12,15],
[19,26,33],
[29,40,51],
[39,54,69]]