Matrix multiplication: Difference between revisions

Line 2,749:
{def mat*mat
{lambda {:a :b}
{#A.new {S.map {{lambda {:a :b :i} // loop on row:i
{#A.new {S.map {{lambda {:a :b :i :j} // loop on col:j
{+ {S.map {{lambda {:a :b :i :j :k} // sumloop ofon prod:k
{* {#A.get :k {#A.get :a :i} :ka}} // of a[i,k]*b[k,j]
{#A.get :j {#A.get :b :k} :jb}}} // and b[k,j]
} :a :b :i :j} {S.serie 0 {- {#A.length :b} 1}} }}
} :a :b :i} {S.serie 0 {- {#A.length {#A.get 0 :b 0}} 1}} }}
} :a :b} {S.serie 0 {- {#A.length :a} 1}} }
}}}
-> mat*mat
{def A {#.new {#.new 1 2}
 
{#.new 3 4}
{def A {A.new {#A.new 51 62}
{#A.new 73 84}}} = [[1,2],[3,4],[5,6],[7,8]]
{def B {#.new {#A.new 1 25 36}
{#A.new 47 5 68}}} = [[1,2,3],[4,5,6]]
-> A
{def AB {#A.new {#A.new 1 2 3}
{#A.new 3 4 5 6}}}
-> B
 
{mat*mat {A} {B}}
-> [[ 9,12,15],
[19,26,33],
[29,40,51],