I am not sure if this is more readable for you (readability depends on
the reader and his/her background), but it is more vectorized.
a=: 10 20 30 40
b=: 3 6 9 12
num=:".;._2
ai=: num 0 : 0
0 1
2 3
2 3
)
bi=: num 0 : 0
1 3
0 2
1 3
)
f=:[: +/@|: (ai{[) * bi{]
cmps=:*&{. , f
a cmps b
2007/5/23, Terrence Brannon <[EMAIL PROTECTED]>:
To be an array processing language, I am surprised to find the Pike code more
readable for this particular problem. Please spruce up my J code.
compose =: 4 : 0
a =. ((0 { x) * (0 { y))
b =. ((0 { x) * (1 { y)) + ((1 { x) * (3 { y))
c =. ((2 { x) * (0 { y)) + ((3 { x) * (2 { y))
d =. ((2 { x) * (1 { y)) + ((3 { x) * (3 { y))
a,b,c,d
)
-- Pike code follows --
array(int) compose(array(int) a, array(int) b)
{
return ({ a[0]*b[0], a[0]*b[1]+a[1]*b[3],
a[2]*b[0]+a[3]*b[2], a[2]*b[1]+a[3]*b[3] });
}
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm