Re: [Jprogramming] Adler-32

2014-08-27 Thread Mike Day
Thanks both. There's been quite a lot of subsequent correspondence about the relative performance of u/\ and u/\.. What I was actually griping about was the relatively poor performance of M&|@:u (distributed across an array in some manner) compared to plain u, as here with add32 cf +

Re: [Jprogramming] Adler-32

2014-08-26 Thread Raul Miller
Hmm... Here's another gerundy example you might want to tag for future reading... http://rosettacode.org/wiki/Odd_word_problem#J Honestly, though, most of this stuff is for play rather than serious work. Then again, the only way you get good at this stuff is if you play with it. Serious work ten

Re: [Jprogramming] Adler-32

2014-08-26 Thread Joe Bogner
On Tue, Aug 26, 2014 at 12:05 PM, Raul Miller wrote: > P.S. example use: > > trampoline 3 peano 5 > 8 > Thank you. This whole thread has pushed me well beyond my comfort zone. I realize that these examples are simply illustrative of the trampoline concept and wouldn't be used in the real worl

Re: [Jprogramming] Adler-32

2014-08-26 Thread Jose Mario Quintana
Raul already described the problem; I often use an adverb (scan) instead of (/\.) to solve this kind of issues: u ( scan=. ((~/)\.)(&.|.) ) u~/\.&.|. Again, the difference between these adverbs can be appreciated by means of symbolic nouns and verbs: ( YS=. <;._1 ' Y0 Y1 .. YN' ) ┌──┬──┬──

Re: [Jprogramming] Adler-32

2014-08-26 Thread Jose Mario Quintana
Raul wrote: " http://weblambdazero.blogspot.com/2010/07/advanced-recursion-in-newlisp.html looks like it is describing this: memoize=: M. " Yes; however, a trampoline function was defined further down. In any case, this is not very relevant now because… Raul wrote: " I should also add an imp

Re: [Jprogramming] Adler-32

2014-08-26 Thread Raul Miller
I should also add an implementation of the "tco" at the very bottom of that post: tco=:(0 :0)(2 :0) : context=. cocreate'' NB. context active__context=: 0 accumulated__context=: '' v 2 :m context ) : accumulated__n=: x,&/pair end. active__n=. 0 value__n end. ) sum=: (4 :0)

Re: [Jprogramming] Adler-32

2014-08-26 Thread Raul Miller
P.S. example use: trampoline 3 peano 5 8 Thanks, -- Raul On Tue, Aug 26, 2014 at 12:04 PM, Raul Miller wrote: > (I thought I sent this message, this morning, but I see that it has not > yet been sent. I have been having this happen a lot recently. I have a > hunch about what is happeni

Re: [Jprogramming] Adler-32

2014-08-26 Thread Raul Miller
(I thought I sent this message, this morning, but I see that it has not yet been sent. I have been having this happen a lot recently. I have a hunch about what is happening, but for now I'll just note that I am having this issue, and I apologize if it seems I am ignoring anyone.) -

Re: [Jprogramming] Adler-32

2014-08-26 Thread 'Pascal Jasmin' via Programming
e of $:, but I'm not sure there is full TCO (completely in place sort), even though it doesn't crash the stack on medium data. - Original Message ----- From: Joe Bogner To: programm...@jsoftware.com Cc: Sent: Tuesday, August 26, 2014 6:10:28 AM Subject: Re: [Jprogramming] Adler-

Re: [Jprogramming] Adler-32

2014-08-26 Thread Joe Bogner
On Mon, Aug 25, 2014 at 9:51 PM, Raul Miller wrote: > http://www.integralist.co.uk/posts/understanding-recursion-in-functional-javascript-programming/#the-solution > looks like it is describing this: > > trampoline=:3 :0 >try. > while. 1 do. > y=. y`:6'' > end. >catch.

Re: [Jprogramming] Adler-32

2014-08-25 Thread 'Pascal Jasmin' via Programming
ound value is only 0 after call. 11    ('blast off!'"_^:(0 = [) ; <:@[) lexT 'f' 11 blast off!     timing is not terrible.  timespacex causes 2 calls to function.    erase 'f' 1    ('blast off!'"_^:(0 = [) ; <:@[) lexT 'f' 1000

Re: [Jprogramming] Adler-32

2014-08-25 Thread Raul Miller
adverbs in general, is that I can type >> boxscan in source code, but the actual definition will be "compiled away" >> as if it were called with f. . using the term boxscan can help with >> readability if the intent of the function is to create a rightmost >> accum

Re: [Jprogramming] Adler-32

2014-08-25 Thread Raul Miller
neat feature regarding tacit adverbs in general, is that I can type >> boxscan in source code, but the actual definition will be "compiled away" >> as if it were called with f. . using the term boxscan can help with >> readability if the intent of the function is to

Re: [Jprogramming] Adler-32

2014-08-25 Thread Jose Mario Quintana
but the actual definition will be "compiled away" > as if it were called with f. . using the term boxscan can help with > readability if the intent of the function is to create a rightmost > accumulator state. > > > > > - Original Message - > From: Raul

Re: [Jprogramming] Adler-32

2014-08-25 Thread Raul Miller
((65521 | {.@:] ({:@:] ,~ [ + +/@:}:@:]) [: +/\ [,~{:@:]) boxscan) > ad32=: 65521 | [: ({: ,~ <:@:+/) ad32c > >ad32 ( ad32c |. 0 0 ; (1, a. i. 'Wik') ; a. i. 'ip') ;~ a. i.'edia' > 4582 920 > > > - Original Message - > Fr

Re: [Jprogramming] Adler-32

2014-08-25 Thread 'Pascal Jasmin' via Programming
27;ip') ;~ a. i.'edia' 4582 920 - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Monday, August 25, 2014 3:15:48 PM Subject: Re: [Jprogramming] Adler-32 On Mon, Aug 25, 2014 at 2:40 PM, 'Pascal Jasmin' via Programming wrote: > boxscan can

Re: [Jprogramming] Adler-32

2014-08-25 Thread Raul Miller
On Mon, Aug 25, 2014 at 2:40 PM, 'Pascal Jasmin' via Programming wrote: > boxscan can use any list of arguments as the x, and appends any > shape as the y, as long x u y results in a shape "compatible with > y" (more accurately compatible with future applications of x u > result . boxscan can use

Re: [Jprogramming] Adler-32

2014-08-25 Thread 'Pascal Jasmin' via Programming
-- Original Message - From: Raul Miller To: Programming forum Cc: Sent: Monday, August 25, 2014 1:16:58 PM Subject: Re: [Jprogramming] Adler-32 I have a nitpick with your phrasing here. Instead of saying "... use / recursively... (tail call optimization)" I think you should say

Re: [Jprogramming] Adler-32

2014-08-25 Thread Raul Miller
510 <\ 1, Randdata' > 0.412953 5.36889e8 >timespacex '(65521 | [: ( {: , <:@:+/) (65521 | {.@:] ({:@:] ,~ [ + > +/@:}:@:]) [: +/\ [,~{:@:]) boxscan) |. 0 0 ; _151 <\ 1, Randdata' > 0.414528 3.77498e8 > > 4096 to 32764 chunks are the fastest, a

Re: [Jprogramming] Adler-32

2014-08-25 Thread 'Pascal Jasmin' via Programming
0.414528 3.77498e8 4096 to 32764 chunks are the fastest, and use the same memory.  4096 would work best on 32 bit J for character data - Original Message - From: bill lam To: 'Pascal Jasmin' via Programming Cc: Sent: Sunday, August 24, 2014 11:04:01 PM Subject: Re: [Jpro

Re: [Jprogramming] Adler-32

2014-08-24 Thread bill lam
; is that it provides the basis for s2 > >    <: +/ 1 88 193 300 405 517 618 718 823 920 > 4582 > > > > - Original Message - > From: 'Pascal Jasmin' via Programming > To: "programm...@jsoftware.com" > Cc: > Sent: Sunday, August 24, 2014

Re: [Jprogramming] Adler-32

2014-08-24 Thread 'Pascal Jasmin' via Programming
;programm...@jsoftware.com" Cc: Sent: Sunday, August 24, 2014 11:48:23 AM Subject: Re: [Jprogramming] Adler-32 sorry that version doesn't work on a stream.  will post one later. - Original Message - From: bill lam To: 'Pascal Jasmin' via Programming Cc: Sent: Sunday

Re: [Jprogramming] Adler-32

2014-08-24 Thread 'Pascal Jasmin' via Programming
sorry that version doesn't work on a stream.  will post one later. - Original Message - From: bill lam To: 'Pascal Jasmin' via Programming Cc: Sent: Sunday, August 24, 2014 11:15:57 AM Subject: Re: [Jprogramming] Adler-32 Did you mean  _4]\  ? Anyway, from the wikiped

Re: [Jprogramming] Adler-32

2014-08-24 Thread bill lam
1, a. i. 'Wikipedia' > 920 4582 > > > > > - Original Message ----- > From: bill lam > To: Programming forum > Cc: > Sent: Sunday, August 24, 2014 7:35:26 AM > Subject: Re: [Jprogramming] Adler-32 > > I realized that my loop tr

Re: [Jprogramming] Adler-32

2014-08-24 Thread 'Pascal Jasmin' via Programming
47 2.68445e8    65521&|@:([: ({: , [: <: +/) +/\)"1 ] _524288 ]/ 1 ,~ Randdata 46312 20147 - Original Message - From: 'Pascal Jasmin' via Programming To: "programm...@jsoftware.com" Cc: Sent: Sunday, August 24, 2014 10:01:41 AM Subject: Re: [Jprogrammin

Re: [Jprogramming] Adler-32

2014-08-24 Thread Raul Miller
On Sun, Aug 24, 2014 at 6:43 AM, mike_liz@tiscali.co.uk wrote: > I continue to be puzzled by the poor performance of something > like add32/\ compared to +/\ . The answer, here, can be explained in terms of an issue which I remember being taught in gradeschool - "the associative law". (Of co

Re: [Jprogramming] Adler-32

2014-08-24 Thread 'Pascal Jasmin' via Programming
reduction at the end.     ([: ({: , [: <: +/) +/\)"1 ] _4 ]/ 1, a. i. 'Wikipedia' 920 4582 - Original Message - From: bill lam To: Programming forum Cc: Sent: Sunday, August 24, 2014 7:35:26 AM Subject: Re: [Jprogramming] Adler-32 I realized that my loop t

Re: [Jprogramming] Adler-32

2014-08-24 Thread bill lam
I realized that my loop translation solution was equally faulty in its final step. It should be ({: (23 b.) 16&(33 b.)@{.) s2,s1 On Aug 24, 2014 6:40 PM, "bill lam" wrote: > J32 should give a 32-bit integer so that the last train > should be > [: ({: (23 b.) 16&(33 b.)@{.) > instead of > 65536

Re: [Jprogramming] Adler-32

2014-08-24 Thread mike_liz....@tiscali.co.uk
What overflow problem I thought when I came up with add32 =: 65521&|@: + NB. add modulo 65521 a32mdslow =: ((1 add32{:)(+ 16 (33 b.)]) (#add32(add32/)))@:(add32/\)@(a.&i.) and then I tested it on modest size input and found it was ORDERS of magnitude slower than Bill's loopy version! So

Re: [Jprogramming] Adler-32

2014-08-24 Thread bill lam
J32 should give a 32-bit integer so that the last train should be [: ({: (23 b.) 16&(33 b.)@{.) instead of 65536#. This shoud be good enough. Thanks. Вс, 24 авг 2014, Jan-Pieter Jacobs написал(а): > You could incorporate the modulo operation in the summation directly: > > As per Raul's solut

Re: [Jprogramming] Adler-32

2014-08-24 Thread Jan-Pieter Jacobs
You could incorporate the modulo operation in the summation directly: As per Raul's solution, with the modulo addition: a32_2=: 65536#. _1 0+ [:((65521|+)/ , {.) [: (65521|+)/\. 1,~ a.i. |. NB. Test on 10M of random data Randdata =: a.{~ ?1000$256 timespacex 'r1=:a32_2 Randdata' 7.26671 2.684

Re: [Jprogramming] Adler-32

2014-08-24 Thread bill lam
Since s2 is quadratic, it overflows quickly in J32. However ieee floating points have 52 bits mantissa, so it can still give correct result for medium size data albeit overflowed. 9!:11[16 (3!:0;]) a32 1e6{.a. Вс, 24 авг 2014, Raul Miller написал(а): > Hmm... actually there might be a floating

Re: [Jprogramming] Adler-32

2014-08-24 Thread Raul Miller
Hmm... actually there might be a floating point overflow problem for gigabyte length arguments. I do not have the patience, however, to find what (for example) adler32 1e9#{:a. is. Thanks, -- Raul On Sun, Aug 24, 2014 at 4:37 AM, Raul Miller wrote: > I believe this is equivalent, and a bit f

Re: [Jprogramming] Adler-32

2014-08-24 Thread Raul Miller
I believe this is equivalent, and a bit faster: a32=: 65536#. 65521| _1 0+ [:(+/ , {.) 65521| [:+/\. 1,~ a.i. |. a32 'Wikipedia' 300286872 a32 'The quick brown fox jumps over the lazy dog' 1541148634 Thanks, -- Raul On Sun, Aug 24, 2014 at 4:05 AM, bill lam wrote: > Does anyone have a

[Jprogramming] Adler-32

2014-08-24 Thread bill lam
Does anyone have a J-ish solution to adler32 checksum and avoid overflow to floating points ? Adler-32 is composed of two sums accumulated per byte: s1 is the sum of all bytes, s2 is the sum of all s1 values. Both sums are done modulo 65521. s1 is initialized to 1, s2 to zero. The Adler-32 check