Question

(2&*~) 15 7 3 1 

Above is the phrase. At the end is the trace and the final outcome. I understand that the phrase is a monad, I understand that because of ~ it has a left and right argument. The same output happens if you run '15 7 3 1(2&*) 15 7 3 1'. I also get that the right table are powers of 2 to the 1, 3, 7, 15, and the other entries are their base number times that power of 2, but I just do not understand why.

On a related note, this is a phrase from ethopian multiplication on the Rosetta Code website (actually this is, as well, I got this far in trying to figure that out) and '(1>.<.@-:)^:a:' is the phrase.

(1>.<.@-:)^:a: 27
27 13 6 3 1

but (1>.<.@-:)^: 27 returns a box'd version of itself and I would expect it to run 27 times.

On a final of three related questions, (these are all related to decomposing the ethopian multiplication code), the complete code is given as:

double =:  2&*
halve  =:  %&2           NB.  or the primitive  -:
odd    =:  2&|

ethiop =:  +/@(odd@] # (double~ <@#)) (1>.<.@halve)^:a:

and that can be trivially substituted as:

ethiop =:  +/@(2&|@] # (2&*~ <@#)) (1>.<.@-:)^:a:

And that works fine! Flushed with success, I fell completely off of the cliff when I thought, there is a monadic double that works on the command line:

+: 98
196

And a double operator has to be faster than a double with an attached constant, maybe double just shifts, so I would think that

ethiop =:  +/@(2&|@] # (+:~ <@#)) (1>.<.@-:)^:a:

Would work...but it does not.

I have tried caps, conjunctions, and so forth, and nothing gets it to work, it always says, "domain error". I am beginning to think that the code depends on the dyadically called monad to create the doubling table in a way I do not get.

The only good thing is that the J verb odd has nothing to do with testing for an odd number.

Can anyone explain these things to me, maybe with an English explanation of how the program works? Not how the algorithm works, how it implements the algorithm. I recall when I was playing with IBM 1130 APL back in 1970. This was an APL interpreter that ran in 8k words, needless to say, it was limited. For example, it had a roll but no deal. The interpreter phased itself in and out of memory, the 1130 supported code overlays, it would separate your subroutines into groups and when one group called another, it would load the new group off of disk (yes, pseudo swapping in 8k). So I wrote versions of deal, using various schemes, and randomly, we would hit one that could phase in and out without seeking, and that version, no matter how badly written with how many lines and how many interpreter actions would run 10 times as fast as any other. I had no idea what I was doing, I would keep adding ravels and meaningless assignments and breaking statements across lines or combining them until I got one that would run without seeking. (A 52 deal 52 that was seeking could take 45 seconds).

And then last night I calculated the 150,000th Fibonacci number in J. It had to be the 64 bit version, and it took one hour, 17 minutes. I used exact arithmetic, the number has 31349 digits and it starts 1012838344936638038...... And I realized that the 1130 could never have calculated this, the number would not have fit, cause you need three of them and the biggest one made had 32k 16 bit words. I want to learn the language that can do this, but there is something missing from the doc that I am just not getting.

 trace '(2&*) 15 7 3 1' 
 --------------- 4 Conj -------
 2
 &
 *
 2&*
 --------------- 3 Adverb -----
 2&*
 ~
 2&*~
 --------------- 8 Paren ------
 (
 2&*~
 )
 2&*~
 --------------- 0 Monad ------
 2&*~
 15 7 3 1
 491520 229376 98304 32768
   1920    896   384   128
    120     56    24     8
     30     14     6     2
 ==============================
 491520 229376 98304 32768
   1920    896   384   128
    120     56    24     8
     30     14     6     2

Fibonacci Footnote:

]t150k=:6!:2 'a150k =: $ ":r150k=: {:  (,+/@(_2&{.) )^:150000 (0x 1x)'
4631.62

0 60 60 #: t150k
1 17 11.6167
r150k
10128383449366380384728502706681008427227914006240871521944866167854579423510169
50198752571599303492471943589300904953648270811064370506598260395645679940891823
17307901573781852234222080308236027906733606532470814177610613237408102006595571
1949713927351702...
a150k
31349

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top