I thought I would polish my J skills by trying to write a function to approximate the infinite sum
1 + 1%2^2 + 1%3^2 + 1%4^2 + 1%5^2 .... NB. First get the integers 1+i. 10 1 2 3 4 5 6 7 8 9 10 NB. Now make a verb "g" that will take a right argument of the number of terms. g =. 1+i. g 10 1 2 3 4 5 6 7 8 9 10 NB. It works! NB. Now to test squaring the integers 2^~1+i. 10 1 4 9 16 25 36 49 64 81 100 NB. Now add that to the verb g =. 2^~1+i. g 10 1 4 9 16 25 36 49 64 81 100 NB. That works! NB. Now test calculating the inverses 1%2^~1+i. 10 1 0.25 0.111111 0.0625 0.04 0.0277778 0.0204082 0.015625 0.0123457 0.01 NB. Add that to the g verb g =. 1%2^~1+i. g 10 1 0.25 0.111111 0.0625 0.04 0.0277778 0.0204082 0.015625 0.0123457 0.01 NB. That works! NB, Now we test summing all the terms up +/1%2^~1+i. 10 1.54977 NB. Yep, that's right for just 10 terms. NB. Double check 1 + (1%2^2) + (1%3^2) + (1%4^2) + (1%5^2) + (1%6^2)+ (1%7^2)+ (1%8^2)+ (1%9^2) + (1%10^2) 1.54977 NB. Yep, everything is OK. NB. Now add the sum insert to the verb g, just like the test g =. +/1%2^~1+i. g 10 11 10.25 10.1111 10.0625 10.04 10.0278 10.0204 10.0156 10.0123 10.01 NB. ;-( the sum didn't work in the verb g! What happened? Skip Skip Cave Cave Consulting LLC On Tue, Apr 12, 2016 at 11:45 AM, R.E. Boss <[email protected]> wrote: > > From: Chat [mailto:[email protected]] On Behalf Of Dan > > Bron > > Sent: dinsdag 12 april 2016 15:47 > > > One of the most memorable and enjoyable examples (for me, anyway) of > > using J for this kind of work was your (REB’s) exploration of Grey Codes > a few > > years back. I distinctly remember writing a Grey Code function I thought > > must be close to the limit in performance, because it used bitwise > functions, > > and was about as close as you could come to writing a C or assembler Grey > > Code program without actually leaving J proper. > > > > But then you went and beat me anyway. By a not insignificant margin. > > This I remember distinctly as well. :-) > (see also http://code.jsoftware.com/wiki/Puzzles/Gray_Code from which I > learned it was Dec 2006) > That was because of mine (I think) superior representation of the (binary > reflected) Gray(!) code, completely inspired by J, a notation which I'm > still struggling to sell to the mathematical/computer-scientist world. > I wrote about it also in > http://journalofj.com/index.php/vol-4-no-2-december-2015 (but I never see > an announcement when a new number is released). > Next time I will reveal the hyper-orthogonal Hilbert curves. > > > R.E. Boss > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
