> [EMAIL PROTECTED] On Behalf Of Roger Hui
> Sent: Wednesday, February 28, 2007 3:20 AM
> To: Programming forum
> Subject: Re: [Jprogramming] Function-level programming
> 
> The Ackermann benchmark is misleading.  Ack made
> use of later results in the essay that you cited,
> results derived using the much simpler ack .

My first encounter with the Ackermann function was a printout of Susan's
page, ( http://www-users.cs.york.ac.uk/~susan/cyc/a/ackermnn.htm )
handled out to me by Devon McCormick more than a decade ago; ever since I
have enjoyed programming and reprogramming it to test my tacit ideas and
techniques a few times.  In Susan's page you can also see the usual
recursive definition and the results that Ack is using. 

> >From the same results, one could define:
> 
> a0=: >:
> a1=: 2&+
> a2=: 3&+@(2&*)
> a3=: 2&^&.(3&+)
> a4=: ^/@(#&2)&.(3&+) " 0
> a5=: 3 : '^/@(#&2)^:(1+y)&.(3&+) 1' :: _: " 0
> ackk=: ([EMAIL PROTECTED])`([EMAIL PROTECTED])`([EMAIL PROTECTED])`([EMAIL 
> PROTECTED])`([EMAIL PROTECTED])`([EMAIL PROTECTED])`(_"0) @. [
> 
> And then, comparing apples to apples:

I wrote,

"
However, although both might be calculating the same output,

[... the full context can be found the end of this message]

their methods are quite different,
 
    ts'ack"0 _/~ 0 1 2 3'
 0.0633287192 19776
    ts'Ack"0 _/~ 0 1 2 3'
 0.000315403215 4288
[...]
"

precisely to indicate that they were apples and oranges (I guess my point
was not so clear to everyone).  As mentioned above, I coded Ack that way for
my enjoyment; its performance was merely a pleasant side effect surprise.

> 
>    (ackk"0 _~ -: Ack"0 _~) 0 1 2 3
> 1
>    (ackk"0 _~ -: Ack"0 _~) i.7
> 1
>    ts 'Ack"0 _~ 0 1 2 3'
> 8.99162e_5 3712
>    ts 'ackk"0 _~ 0 1 2 3'
> 3.20388e_5 3392
>    ts 'Ack"0 _~ i.7'
> 1.36114 19904
>    ts 'ackk"0 _~ i.7'
> 0.141217 531776
> 
> Regarding Ack.  As a courtesy to the reader, one
> could define it using components with little if
> any loss in efficiency.  And if you did define it
> using components but posted to the forum the
> result of applying f. , you have even less excuse.

As a courtesy to the interested reader without a severe case of arthritis I
included a link,

"
You can find an example of this approach in
http://www.jsoftware.com/pipermail/general/2006-January/026196.html (find
Ackermann close to the end of the message).
"

where, both, a version using components and its fixed version appear.

(
 
By the way, the text you referred followed between parentheses.

)

Not withstanding how much I enjoy joggling, I have to re-focus back my full
attention to the markets for a while given yesterday's meltdown.
   

> 
> f03 =: {::&(<;._1 ' >: 2&+&.(3&+) 2&*&.(3&+) 2&^&.(3&+)')
> fx  =: '-&3@:(] (' , ] , ')&.(-&3)@:]^:(>:@:[)4:)'"_
> f4n =: ] fx^:([-3:) [EMAIL PROTECTED]:
> Ack1=: (f03 :: f4n)@[ 128!:2 ]
> 
>    (Ack1"0 _~ -: Ack"0 _~) i.7
> 1
>    ts 'Ack1"0 _~ i.7'
> 1.36694 19904
> 
> 
> --------------------------------------
> 
> >From         Jose Mario Quintana <[EMAIL PROTECTED]>
> Sent          Tuesday, February 27, 2007 2:56 pm
> To    'Programming forum' <[email protected]>
> Subject       RE: [Jprogramming] Re: Function-level programming
> 
> ....
> You can find an example of this approach in
> http://www.jsoftware.com/pipermail/general/2006-January/026196.html (find
> Ackermann close to the end of the message).
> 
> (
> 
> By the way, one can see that
> 
>      Ack=. (0&({::) {:: 1&({::)) ::(0&({::) ('-&3@:(] ('"_ , ] ,
> ')&.(-&3)@:]^:(>:@:[)4:)'"_)@:]^:([ - 3:) _1:
> {::1&({::))@:(<@(<;._1@('`'&,)@('>:`(2&+&.(3&+))`(2&*&.(3&+))`(2&^&.(3&+))
> '"
> _))1} ])@:('.'&(] , ;:@:[)@:<)@[ 128!:2 ]
> 
> is verbose relative to (
> http://www.jsoftware.com/jwiki/Essays/Ackermann%27s_Function ),
> 
>     ack=: c1`c1`c2`c3 @. (#.@(,&*))
>     c1=: >:@]                        NB. if 0=x, 1+y
>     c2=: <:@[ ack 1:                 NB. if 0=y, (x-1) ack 1
>     c3=: <:@[ ack [ ack <:@]         NB. else,   (x-1) ack x ack y-1
> 
> However, although both might be calculating the same output,
> 
>    ack"0 _/~ 0 1 2 3
> 1  2  3  4
> 2  3  4  5
> 3  5  7  9
> 5 13 29 61
>    Ack"0 _/~ 0 1 2 3
> 1  2  3  4
> 2  3  4  5
> 3  5  7  9
> 5 13 29 61
> 
> their methods are quite different,
> 
>    ts'ack"0 _/~ 0 1 2 3'
> 0.0633287192 19776
>    ts'Ack"0 _/~ 0 1 2 3'
> 0.000315403215 4288
> 
>    ts'ack"0 _/~ 0 1 2 3 4'
> |stack error: c1
>    ts'Ack"0 _/~ 0 1 2 3 4'
> 0.00040088894 9088
> 
>    ts'Ack"0 _/~ 0 1 2 3 4 5 6'
> 4.78145155 20544
>    Ack"0 _/~ 0 1 2 3 4 5 6
>     1     2  3  4   5   6   7
>     2     3  4  5   6   7   8
>     3     5  7  9  11  13  15
>     5    13 29 61 125 253 509
>    13 65533  _  _   _   _   _
> 65533     _  _  _   _   _   _
>     _     _  _  _   _   _   _
> 
> )
> 
> ...
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to