On the same topic (of premature optimization), Ken had this to say
in his Turing lecture   http://keiapl.org/anec/#Turing_lecture1

The practice of first developing a clear and precise definition 
of a process without regard to efficiency, and then using it 
as a guide and a test in exploring equivalent processes 
possessing other characteristics, such as greater efficency, 
is very common in mathematics. It is a very fruitful practice 
which should not be blighted by premature emphasis on 
efficiency in computer execution.

Measures of efficiency are often unrealistic because they 
concern counts of “substantive” functions such as 
multiplication and addition, and ignore the housekeeping 
(indexing and other selection processes) which is often 
greatly increased by less straightforward algorithms. 
Moroever, realistic measures depend strongly on the 
current design of computers and of language embodiments. 
For example, because functions on booleans (such as ∧/B 
and ∨/B) are found to be heavily used in APL, 
implementers have provided efficient execution of them. 
Finally, overemphasis of efficiency leads to an unfortunate 
circularity in design: for reasons of efficiency early 
programming languages reflected the characteristics 
of the early computers, and each generation of computers 
reflects the needs of the programming languages 
of the preceding generation.



----- Original Message -----
From: Devon McCormick <[EMAIL PROTECTED]>
Date: Tuesday, July 1, 2008 9:35
Subject: Re: [Jprogramming] Random number generation
To: Programming forum <[email protected]>

> Proving once again that "premature optimization is the root of 
> all evil."
> (Tony Hoare)
> 
> On 7/1/08, Roger Hui <[EMAIL PROTECTED]> wrote:
> >
> > Timing is not everything.  In this case f2 is computing
> > something weird and possibly misleading:  All the
> > elements of a row are the same. e.g.
> >
> >    f2 3 4$9
> > 2.06843 2.06843 2.06843 2.06843
> > 5.20443 5.20443 5.20443 5.20443
> > 1.00311 1.00311 1.00311 1.00311
> >    f3 3 4$9
> >   3.36383 8.62184  6.76132 4.76392
> >   8.01329 7.10008 0.285073 3.84514
> > 0.950537 6.16313 0.214141 3.56592
> >
> >
> >
> >
> > ----- Original Message -----
> > From: "R.E. Boss" <[EMAIL PROTECTED]>
> > Date: Monday, June 30, 2008 23:56
> > Subject: RE: [Jprogramming] Random number generation
> > To: 'Programming forum' <[email protected]>
> >
> > >    f3=: 3 : 'y * ($y) [EMAIL PROTECTED] 0'
> > >    f2=: 3 : 'y * ?(#y)#0'
> > >
> > >    ts 'f2 Y' [Y=:1000 1000$9
> > > 0.0098060407 8402944
> > >    ts 'f3 Y'
> > > 0.034617353 16781696
> > >
> > >
> > > R.E. Boss
> > >
> > >
> > > > -----Oorspronkelijk bericht-----
> > > > Van: [EMAIL PROTECTED] [mailto:programming-
> > > > [EMAIL PROTECTED] Namens Joey K Tuttle
> > > > Verzonden: maandag 30 juni 2008 19:41
> > > > Aan: Programming forum
> > > > Onderwerp: Re: [Jprogramming] Random number generation
> > > >
> > > > Interestingly, I see almost no change in speed/space between
> > > (my) f2 and
> > > > f3...
> > > >
> > > >     ts 'f2 1000 1000$9'
> > > > 0.231313 2.20224e7
> > > >     ts 'f3 1000 1000$9'
> > > > 0.235067 2.0974e7
> > > >
> > > > Well - I guess a million bytes in space saving is
> > > > nothing to sneeze at (used to be a lot of
> > > > memory...) so I applaud the optimization work you
> > > > have done!
> > > >
> > > > Thanks - joey
> > > >
> > > > At 10:08  -0700 2008/06/30, Roger Hui wrote:
> > > > >To gain more speed (and reduce space), use:
> > > > >
> > > > >f3=: 3 : 'y * ($y) [EMAIL PROTECTED] 0'
> > > > >
> > > > >[EMAIL PROTECTED] is supported by special code.  The difference
> > > > >is most striking for random booleans:
> > > > >
> > > > >    ts=: 6!:2 , 7!:[EMAIL PROTECTED]
> > > > >
> > > > >    ts '1e6 [EMAIL PROTECTED] 2'
> > > > >0.00275063 1.04934e6
> > > > >    ts '?1e6$2'
> > > > >0.00555685 5.24352e6
> > > > >
> > > > >
> > > > >
> > > > >----- Original Message -----
> > > > >From: Joey K Tuttle <[EMAIL PROTECTED]>
> > > > >Date: Monday, June 30, 2008 8:54
> > > > >Subject: RE: [Jprogramming] Random number generation
> > > > >To: Programming forum <[email protected]>
> > > > >Cc: 'Programming forum' <[email protected]>
> > > > >
> > > > >>  Not to quibble... but
> > > > >>
> > > > >>      f2 =: 3 : 'y * ?(#y)#0'
> > > > >>
> > > > >>  has a related trouble to the original post with
> > > > >>  argument rank > 1 ... f1 is actually better in
> > > > >>  extending "to work with arrays of any shape". To
> > > > >>  try to gain some speed, perhaps you really meant
> > > > >>  to say:
> > > > >>
> > > > >>      f2 =: 3 : 'y * ?($y)$0'
> > > > >>
> > > > >>  - joey
> > > > >>
> > > > >>
> > > > >>  At 10:59  -0400 2008/06/30, Henry Rich wrote:
> > > > >>  >What you executed was:
> > > > >>  >
> > > > >>  >3 3 * ?0
> > > > >>  >
> > > > >>  >which is
> > > > >>  >
> > > > >>  >3 3 * (?0)
> > > > >>  >
> > > > >>  >in other words, you asked for one number, then
> > > multiplied it by
> > > > >>  3 twice.
> > > > >>  >
> > > > >>  >
> > > > >>  >You could have your verb apply to atoms by 
> giving it
> > > a rank of 0:
> > > > >>  >
> > > > >>  >    f1 =: 3 : 'y * ?0'"0
> > > > >>  >
> > > > >>  >Or, you could design it to work with arrays of 
> any shape:
> > > > >>  >
> > > > >>  >    f2 =: 3 : 'y * ?(#y)#0'
> > > > >>  >
> > > > >>  >Working with bigger arrays is faster, but perhaps
> > > not by enough
> > > > >>  >to be worth the trouble.  Depends on your
> > > application.> >>  >
> > > > >>  >Henry Rich
> > > > >>  >
> > > > >>  >
> > > > >>  >>  -----Original Message-----
> > > > >>  >>  From: [EMAIL PROTECTED]
> > > > >>  >>  [mailto:[EMAIL PROTECTED]
> > > On Behalf Of
> > > > >>  >>  Benoît Roesslinger
> > > > >>  >>  Sent: Monday, June 30, 2008 10:46 AM
> > > > >>  >>  To: [email protected]
> > > > >>  >>  Subject: [Jprogramming] Random number 
> generation> > > >>  >>
> > > > >>  >>  Hi,
> > > > >>  >>
> > > > >>  >>  I am new to J and when doing some
> > > experiments with random
> > > > >>  >>  number generation
> > > > >>  >>  I stumbled across the following behavior,
> > > which wasn't what
> > > > >>  >>  I'd expect :
> > > > >>  >>
> > > > >>  >>     f=: 3 : 'y * ?0'
> > > > >>  >>     f 3
> > > > >>  >>  2.91414
> > > > >>  >>     f 3
> > > > >>  >>  0.139888
> > > > >>  >>     f 3
> > > > >>  >>  0.990328
> > > > >>  >>
> > > > >>  >>  OK so far, but when I tried:
> > > > >>  >>
> > > > >>  >>     f 3 3
> > > > >>  >>
> > > > >>  >>  it gives me :
> > > > >>  >>
> > > > >>  >>  0.0403801 0.0403801 (same values!)
> > > > >>  >>
> > > > >>  >>  whereas I'd expect a behavior much like the
> > > one of '?'...
> > > > >>  >>  Is this behavior normal ?
> > > > >>  >>  Suppose I want to create a function to
> > > generate a random
> > > > >>  >>  deviate from a
> > > > >>  >>  distribution (normal for instance) with some
> > > parameters (mean
> > > > >>  >>  and sd for
> > > > >>  >>  instance) that will work in the same fashion
> > > as '?', ie
> > > > >>  it is
> > > > >>  >>  possible to
> > > > >>  >>  generate lots of random deviates at once
> > > using code
> > > > >>  such as :
> > > > >>  >>  distri 100 $
> > > > >>  >>  x, where x would represent parameters, what
> > > is the best
> > > > >>  way to go ?
> > > > >>  >>
> > > > >>  >>  Many thanks in advance!
> > > > >>  >>
> > > > >>  >>  Benoît.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to