Greetings,
Thanks for J, I've enjoyed programming in it very much.
Here are few more remarks about the reducing/folding from LISP/Haskel
(reduce, ironically, comes from APL). Such operation in its full generality
is perhaps
not very natural in J, but nonetheless should provide some extra
functionality as has already been mentioned in other posts.
Reduce can be implemented as an adverb as well as a conjuction.
Here are examples and definitions:
1) Matrix multiplication:
mp=:+/ .*
mpp=:[+mp
With "reduce" adverb R. , mpp~ could be written as:
mppt=:([+*)R.
Definition of R. would be:
Rank _1 _ _1
x f R. y <-> (...(x f y1)f y2)...)f yn, where n=#y
   f R. y <-> (...(  f y1)f y2)...)f yn
2) Gramm-Schmidt orthonormalization:
(in this example I couldn't find an elegant J code without reduce/fold)
norm=:%%:@mp~
orth=:]-+/@(mp*[)
GS=: monad : 0
   v=.,:[EMAIL PROTECTED]
   i=.1
   while.i<#y do.
     v=.v,norm(v orth i{y)
     i=.>:i
   end.
   v
)
with R. adverb one would write:
GS1=:,:@[EMAIL PROTECTED]([,[EMAIL PROTECTED])R.}.
----------------------------------------------------------
Even better would be perhaps to define R. as a conjuction:
x f R. g y <-> x ([f g)R. y
in this case, however, there is more flexibility to
define the rank of R. based on ranks of f and g.
(in analogy with . )
Now:
1) Matrix multiplication with addition:
mppt1=: +R.*
2) Gramm-Schmidt Orthonormalization:
GS2=: ,:@[EMAIL PROTECTED] ,R.([EMAIL PROTECTED]) }.
Best Regards,
Viktor
--
View this message in context:
http://www.nabble.com/reduce-fold-in-J-as-an-adverb-or-conjuction-tf4839217s24193.html#a13844580
Sent from the J General mailing list archive at Nabble.com.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm