Peter Kessler writes:

> For example, I love the use of "+/\" in the above to propagate the state
of the match.
> (Though, I worry a little about the efficiency of it, if prefix really
reapplies the verb to
> each of the possible prefixes, especially as the inputs get long.)

See Appendix B of the
dictionary<http://www.jsoftware.com/help/dictionary/special.htm>.  If
the definition implies an O(n^2) computation but there is an
alternative O(n) or O(n*^.n) implementation, chances are the faster
implementation would have been done already by special code.  In any case,
the J user can readily answer this sort of question by running a simple
benchmark:

   timer=: 6!:2

   ] t=: 3 : 'timer ''+/\a'' [ a=.y?@$0'"0 ] n=: 1e4 * 2 ^ i.7
0.000123759 0.000225448 0.000207568 0.000373511 0.00126888 0.00315096
0.00598093

   load 'plot'
   plot n;t

Looks pretty linear to me.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to