I was working with R. E.'s compact implementation of the Levenshtein
distance and I found an interesting equivalence:
(<. >:)/\.&.|.
can be replaced by
(<./\@:- + ]) i...@#
which uses a little more space but is quite a bit faster for large
operands. So now I have the version:
NB. Levenshtein distance between two strings
levdist=: 4 : 0
'a b'=. (/: #&>)x;y
z=. i.>:#b
for_j. a do.
z=. ((<./\@:- + ]) i...@#) ((j ~: b) + }:z) ({...@] , (<. }.)) >:z
end.
{:z
)
Henry Rich
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm