Greetings.  I have a question about insert (/).  I've been trying to
insert a simple verb (foo, below) into an array of randomly-chosen
numbers.  The verb performs addition--but with the result clamped to
1-100.  I need to know at what point the sum (which will be bouncing
around because some of the random numbers are negative) hits 100.  (I'm
willing to use i. for that; I don't mind if I generate extra,
unnecessary random numbers.  That's not the problem at this point.)

 

foo =: 4 : 0

NB. x is a total

NB. y is an increment

NB. return a new total 1..100

1 >. (x + y) <. 100

)

 

load 'plot'

plot k=.foo/\d=.(?200$6) { _1 2 _3 4 _5 6

 

You wind up with a very strange plot: Long sequences of identical
numbers, which can't(?) happen given that none of the incremental random
numbers is zero.  Also it slopes upward almost exclusively.

 

I'll guess at the solution: / is implemented in parallel, not
sequentially (in some sense--I know my CPU is actually sequential).  So
I'm not proceeding sedately from number to number, left to right; I'm
actually getting some weird artifact of parallelism, which can't handle
the clipping properly since it's working with partial, independently
clipped sums.  (If that's the case, I should be chastised for thinking
sequentially, which I believe is a sin in J.)  Or something.  Any help
greatly appreciated.

 

Ed

 

 

Ed Gottsman

Accenture Technology Labs

161 N. Clark St.

Chicago, IL 60601

Cell: 847-274-0320

AIM: gottsman63

[EMAIL PROTECTED]

Blog: http://www.accenture.com/gottsman
<http://www.accenture.com/gottsman> 

 



This message is for the designated recipient only and may contain privileged, 
proprietary, or otherwise private information.  If you have received it in 
error, please notify the sender immediately and delete the original.  Any other 
use of the email by you is prohibited.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to