Re: [Jprogramming] Ragged Array Shapes are Trees

2014-09-08 Thread Raul Miller
It is, nevertheless, an implementation.

And anyone that feels like doing so can supply other alternates (or
replace it, if they feel theirs is good enough).

Thanks,

-- 
Raul


On Mon, Sep 8, 2014 at 5:28 PM, Devon McCormick  wrote:
> This looks like a transliteration from another language - not J-like at
> all.  Once clue is that it's several times as long as many of the other
> implementations.
>
>
> On Mon, Sep 8, 2014 at 4:05 PM, Joe Bogner  wrote:
>
>> I found an implementation of red-black trees on rosettacode:
>> http://rosettacode.org/wiki/Pattern_matching#J  ... It might be relevant
>> or
>> may not be.
>>
>> On Mon, Sep 8, 2014 at 3:45 PM, Devon McCormick 
>> wrote:
>>
>> > A little research clarified what we see here: apparently it's part of the
>> > definition of a binary tree that the left node be smaller than its parent
>> > but the right one is greater.  Right away, I see a problem for the
>> > predecessor-index representation of a tree that I'm advocating as it does
>> > not distinguish between right and left nodes as it is usually
>> implemented.
>> >
>> >
>> > On Mon, Sep 8, 2014 at 3:03 PM, Devon McCormick 
>> > wrote:
>> >
>> > > Do you have a reference to a good example of this?  Looking at the
>> > > "before" and "after"  pictures on the right here -
>> > > http://en.wikipedia.org/wiki/Self-balancing_binary_search_tree - the
>> > > rebalancing seems arbitrary as it preserves some relations but changes
>> > > others.
>> > >
>> > >
>> > > On Mon, Sep 8, 2014 at 2:30 PM, Dan Bron  wrote:
>> > >
>> > >> Raul wrote:
>> > >> > Note that J already supports trees.
>> > >>
>> > >> Devon wrote:
>> > >> > I have J code that uses trees which I run daily and
>> > >> > have been doing so for years.
>> > >>
>> > >> Pascal wrote:
>> > >> >  I think trees are done at least ok, if not "right" already.
>> > >>
>> > >> Challenge: express, in J, the logic of rebalancing a heap (say, a
>> > >> Fibonacci
>> > >> heap, but I'm not particularly picky).
>> > >>
>> > >> For the sake of this exercise, you may ignore considerations of
>> > efficiency
>> > >> (though that's a bit of a self-contradiction, because heaps are
>> > frequently
>> > >> introduced specifically for the sake of efficiency). I am only
>> > interested
>> > >> in the directness, simplicity, elegance (lyricality) of the notation,
>> in
>> > >> its current form, for expressing ideas about trees.  We can make it
>> > >> efficient "later" (Pepe's TCO utility is a start).
>> > >>
>> > >> -Dan
>> > >>
>> > >>
>> > >>
>> > >> --
>> > >> For information about J forums see
>> http://www.jsoftware.com/forums.htm
>> > >>
>> > >
>> > >
>> > >
>> > > --
>> > > Devon McCormick, CFA
>> > >
>> > >
>> >
>> >
>> > --
>> > Devon McCormick, CFA
>> > --
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> >
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
>
>
> --
> Devon McCormick, CFA
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Ragged Array Shapes are Trees

2014-09-08 Thread Raul Miller
Point taken.

But neither you nor I (for example) have bothered to be interested
enough in Red Black trees to implement anything better. And for a
problem that size, it's really not right to put an hour into
criticizing it when an hour could have been used to show what you mean
using an actual implementation.

And when you have a working implementation to test against, and a
simple specification like that, if it takes longer than an hour for
someone familiar with J to implement something better is it really
fair to call that approach "better"?

Thanks,

-- 
Raul

On Mon, Sep 8, 2014 at 7:06 PM, Dan Bron  wrote:
> Yes, but to Devon's point, having a direct transliteration of an algorithm 
> originally expressed in a (very) different language doesn't tell us anything 
> about J's power (or not) to express that algorithm.
>
> Any programming language worth discussing is Turing complete. Which means 
> they're all *capable* of expressing anything computable (which means anything 
> you, a human, could do with a sufficient supply of paper, pencils, and time). 
> Each can express anything any of the others can express.
>
> So asking "can J express X?" isn't the interesting question (the answer is 
> "yes"). The interesting question is: what does J make it *simple* to express? 
>  And, by implication (because several of the most fundamental theories humans 
> have developed to date, and all of human experience prior to that, tell us 
> that every decision is a tradeoff, and every benefit comes at a cost), what 
> does it make harder to express?
>
> You will note that Thomas' excellent contribution achieves its practical 
> results by implementing a stack language (that is, another programming 
> language) inside of J.
>
> -Dan
>
> PS: It's worth pointing out that you yourself (Raul) have drawn the 
> distinction between "doable, practically speaking" and "convenient" (or may I 
> say, "elegant"?) in your proposed enhancements to FSM (dyad ;:):
>
> http://www.jsoftware.com/pipermail/chat/2014-January/005653.html
>
> And, for whatever it's worth, I agree with you:
>
> http://www.jsoftware.com/pipermail/general/2005-September/024446.html
>
> Please excuse typos; sent from a phone.
>
>> On Sep 8, 2014, at 6:37 PM, Raul Miller  wrote:
>>
>> It is, nevertheless, an implementation.
>>
>> And anyone that feels like doing so can supply other alternates (or
>> replace it, if they feel theirs is good enough).
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>>> On Mon, Sep 8, 2014 at 5:28 PM, Devon McCormick  wrote:
>>> This looks like a transliteration from another language - not J-like at
>>> all.  Once clue is that it's several times as long as many of the other
>>> implementations.
>>>
>>>
>>>> On Mon, Sep 8, 2014 at 4:05 PM, Joe Bogner  wrote:
>>>>
>>>> I found an implementation of red-black trees on rosettacode:
>>>> http://rosettacode.org/wiki/Pattern_matching#J  ... It might be relevant
>>>> or
>>>> may not be.
>>>>
>>>> On Mon, Sep 8, 2014 at 3:45 PM, Devon McCormick 
>>>> wrote:
>>>>
>>>>> A little research clarified what we see here: apparently it's part of the
>>>>> definition of a binary tree that the left node be smaller than its parent
>>>>> but the right one is greater.  Right away, I see a problem for the
>>>>> predecessor-index representation of a tree that I'm advocating as it does
>>>>> not distinguish between right and left nodes as it is usually
>>>> implemented.
>>>>>
>>>>>
>>>>> On Mon, Sep 8, 2014 at 3:03 PM, Devon McCormick 
>>>>> wrote:
>>>>>
>>>>>> Do you have a reference to a good example of this?  Looking at the
>>>>>> "before" and "after"  pictures on the right here -
>>>>>> http://en.wikipedia.org/wiki/Self-balancing_binary_search_tree - the
>>>>>> rebalancing seems arbitrary as it preserves some relations but changes
>>>>>> others.
>>>>>>
>>>>>>
>>>>>>> On Mon, Sep 8, 2014 at 2:30 PM, Dan Bron  wrote:
>>>>>>>
>>>>>>> Raul wrote:
>>>>>>>> Note that J already supports trees.
>>>>>>>
>>>>>>> Devon wrote:
>>>>>>>> I have J code that uses trees which I run daily and
>>>>>&

Re: [Jprogramming] Ragged Array Shapes are Trees

2014-09-08 Thread Raul Miller
Given what I understand of your style, I think you are looking for
   h=: 13 :'([: < [:$>)"0 y'

Thanks,

-- 
Raul

On Mon, Sep 8, 2014 at 7:51 PM, Linda Alvord  wrote:
>
> How can you define h to use the definition of  &, so that the result is the 
> same as that for  f  and  g :
>
> ]A=:((i.2 3);(,0)) ; (i. 2 3)
> ┌─┬─┐
> │┌─┬─┐│0 1 2│
> ││0 1 2│0││3 4 5│
> ││3 4 5│ ││ │
> │└─┴─┘│ │
> └─┴─┘
>
>f=: 13 :'$ each y'
>f A
> ┌─┬───┐
> │2│2 3│
> └─┴───┘
>
>g=: 13 :'$&.>y'
>g A
> ┌─┬───┐
> │2│2 3│
> └─┴───┘
>
>NB.   u&.v y ↔ vi u v y
>
>h=: 13 :'<"1 ([:$>)"0 y'
>h A
> ┌───┬───┐
> │2 0│2 3│
> └───┴───┘
>
> Linda
> -Original Message-
> From: programming-boun...@forums.jsoftware.com 
> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Michal D.
> Sent: Monday, September 08, 2014 11:01 AM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Ragged Array Shapes are Trees
>
> Thanks Pascal, that's a nice formulation for the 2-level deep case.  It
> breaks down of course for deeper nesting but could serve as a base.
>
> ([:|. $ ;~ $ each) ((i.2 3);(,0)) ; (i. 2 3)
> +-+---+
> |2|+-+---+|
> | ||2|2 3||
> | |+-+---+|
> +-+---+
>
> There's no specific problem I'm trying to solve directly in J at the
> moment.  It's more of a language design problem.  My interest in this is a
> J like language, but with shapes extended to support ragged arrays without
> boxing.  Failing that, we could have some optimization guarantees like 'an
> array of boxes containing equal rank values are allocated contiguously'.
>
> Cheers,
>
> Mike
>
>
>
> On Sat, Sep 6, 2014 at 9:28 AM, 'Pascal Jasmin' via Programming <
> programm...@jsoftware.com> wrote:
>
>> Hi Michal,
>>
>> maybe this is an interesting representation for what you want?
>>
>>([:|. $ ;~ $ each) (i. 2 3) ; (,0) ; 0 1
>> ┌─┬─┐
>> │3│┌───┬─┬─┐│
>> │ ││2 3│1│2││
>> │ │└───┴─┴─┘│
>> └─┴─┘
>>
>>
>>
>> - Original Message -
>> From: Michal D. 
>> To: programm...@jsoftware.com
>> Cc:
>> Sent: Saturday, September 6, 2014 12:06 PM
>> Subject: [Jprogramming] Ragged Array Shapes are Trees
>>
>> I just came to the realization that ragged array shapes, regardless of how
>> you want to represent them, are trees.  I would be interested in any
>> references to prior exploration of this idea.
>>
>> Some example data (boxes are used to display ragged arrays, but otherwise
>> have no semantic meaning):
>>
>>] A =. i. 2 3
>> 0 1 2
>> 3 4 5
>>] B =. (< @ i."0) 1+i.2
>> +-+---+
>> |0|0 1|
>> +-+---+
>>] C =. A ; B
>> +-+-+---+
>> |0 1 2|0|0 1|
>> |3 4 5| |   |
>> +-+-+---+
>>] D =. A ; < B
>> +-+---+
>> |0 1 2|+-+---+|
>> |3 4 5||0|0 1||
>> | |+-+---+|
>> +-+---+
>>
>> The corresponding shape trees (monospace font required, root node is on the
>> left):
>>
>> A: 2 - 3
>>
>>1
>>  /
>> B: 2
>>  \
>>2
>>
>>2 - 3
>>  /
>> C: 3 - 1
>>  \
>>2
>>
>>2 - 3
>>  /
>> D: 2   1
>>  \   /
>>2
>>  \
>>2
>>
>> In some sense the shape tree for A is compressed, the verbose alternative
>> being:
>>
>>3
>>  /
>> A: 2
>>  \
>>3
>>
>> Compressing D in a similar manner leaves the full shape of the tree
>> ambiguous - there is no way to distinguish the duplicate structure of leaf
>> 3 from the structure of leaves 1, 2.
>>
>>3
>>  /
>> D: 2 - 2 - 1
>>  \
>>2
>>
>> We could resolving this ambiguity by listing the shapes of all the items
>> explicitly.  The problem here is that 'compression' could very easily lead
>> to an increase in representation size, although it is nice and uniform for
>> ragged arrays of uniform rank.
>>
>> 3
>>   /
>>  |  3
>>  | /
>> D: 2 - 2 +
>>  | \
>>  |  1
>>   \
>> 2
>>
>> Regardless of compression, I would be interested in prior work in
>> representing shapes of ragged arrays as trees.
>>
>> Cheers,
>>
>> Mike
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Ragged Array Shapes are Trees

2014-09-09 Thread Raul Miller
I've worked with a representation sort of like that, but [in my
opinion] considerably more efficient and flexible.

I'll model the two main routines here:

ssdir=:3 :0
   assert. 1=#$y
   (}:,.2 -~/\])I.(={.)(,{.)y
)

ssndx=:4 :0
   assert. 1=#$y
   assert. 2=#$x
   assert. 2={:$x
   (;<@(+i.)/"1 x){y
)

Example use:

   ssdir ' this is a test'
 0 5
 5 3
 8 2
10 5

   ex=: ' this is a test'
   ((0 3{ssdir) ssndx ]) ex
 this test

In other words, ssndx was analogous to { in design.

Other notes:

(0) the 'ss' part stood for Segmented String.

(1) This was something like 20 years ago, using APL.

(2) we had compiled APL back then, for a rank 0 subset of APL (and
with type inference within that mini language - anything which
constrained a type was equivalent to a type declaration), I think our
first implementations of this code were using that compiled APL
mechanism (but then I think it was redone in assembly language - I"m a
bit foggy on the details at this point, but I do remember that
performance was decent).

(3) There was an additional constraint on the code, in the final
version, such that only type character was supported. We were mostly
interested in working with text (we were building search engines and
related stuff ... Google's emphasis on map-reduce algorithms seems
like a rather straightforward and obvious development from my
perspective). But it's easy enough to build another one (not quite as
fast as the hand assembled version) to work on other types.

[Actually, I'll have to admit that I haven't been really impressed
with a lot of the advancement of state of the art our industry. It's
been looking like a lot of activity but most of the work (including my
own) just has not impressed me as being all that significant. There
have been significant improvements, of course, but not in proportion
to the number of people employed by the industry.]

Anyways... that's just two primitives, but they are quite flexible.
You can replace ssdir with other mechanisms in some contexts, for
example. And you can perform operations on the underlying characters
and then use ssndx to or straight indexing to extract it in a useful
form. (Obviously you'll need a lot more code, but this alleviated a
significant performance bottleneck.)

Thanks,

-- 
Raul

On Tue, Sep 9, 2014 at 1:13 AM, Michal D.  wrote:
> One can imagine that it's possible for
>
>] x =. (<@i."0) 1+i.3
> +-+---+-+
> |0|0 1|0 1 2|
> +-+---+-+
>
> to be laid out in memory as [0 0 1 0 1 2] with an additional vector
> representing the starting point of each rank-1 array [0 1 3 6].  I would be
> willing to wager a large sum that this is much more computationally
> efficient than having a representation where each rank-1 array is floating
> off somewhere in memory [0] [0 1] [0 1 2] with an array of pointers to them.
>
> Of course this representation is possible, but somewhat verbose, to do
> manually in J (http://dl.acm.org/citation.cfm?id=804488).  That's why I'm
> fantasizing about a language where such a representation would be closer to
> the core of the language.
>
> Something like +/"1 x instead of +/&.> x (obviously there's not much
> difference here).
>
> Like we've both suggested, it may be that boxing with a sufficiently
> optimized interpreter is the solution.
>
> Cheers,
>
> Mike
>
> On Mon, Sep 8, 2014 at 8:10 AM, Raul Miller  wrote:
>
>> What does this mean "shapes extended to support ragged arrays without
>> boxing"?
>>
>> K has ragged arrays without boxing, but K's concept of shape only
>> applies to the non-ragged prefix dimensions.
>>
>> Meanwhile, it seems to me that the guarantee you suggest would be
>> computationally expensive.
>>
>> (Not saying the ideas shouldn't be explored, but I suspect what you
>> are really after is a more efficient boxing implementation and that
>> will lead in an entirely different direction.)
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Mon, Sep 8, 2014 at 11:01 AM, Michal D. 
>> wrote:
>> > Thanks Pascal, that's a nice formulation for the 2-level deep case.  It
>> > breaks down of course for deeper nesting but could serve as a base.
>> >
>> > ([:|. $ ;~ $ each) ((i.2 3);(,0)) ; (i. 2 3)
>> > +-+---+
>> > |2|+-+---+|
>> > | ||2|2 3||
>> > | |+-+---+|
>> > +-+---+
>> >
>> > There's no specific problem I'm trying to solve directly in J at the
>> > moment.  It's more of a language design problem.  My interest in this is
>> a
>> > J like language, but with shapes exte

Re: [Jprogramming] Ragged Array Shapes are Trees

2014-09-09 Thread Raul Miller
On Tue, Sep 9, 2014 at 1:50 PM, David Leibs  wrote:
> This influenced APL2. Some say that this caused "a schism" in the APL
> community.

Anything which puts infinity n the "must use routinely" path is going to cause
schisms.

There's an infinity of ways of dealing with infinities, and people can only do
so much.

Then again, some people like schisms.

They are probably best left alone (as much as they will allow).

Thanks,

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


Re: [Jprogramming] Ragged Array Shapes are Trees

2014-09-09 Thread Raul Miller
On Tue, Sep 9, 2014 at 6:45 PM, David Leibs  wrote:
> I just think the Array Theory body work is worth looking at and
> understanding as it is a very interesting bit of the history of APL.
> "Nested Array Theory" gives you nested arrays without any need for boxing
> or unboxing.

That's sort of like saying that Iverson's approach gives you boxed
arrays without any need for nested arrays.

> I think of Array Theory as the wisdom of the ancients. Heck, I am an
> ancient. :-)

I tend to think of it as a distraction from solving useful problems.

Thanks,

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


Re: [Jprogramming] Ragged Array Shapes are Trees

2014-09-09 Thread Raul Miller
Just use http://kx.com/software-download.php if that is what you want?

Thanks,

-- 
Raul

On Tue, Sep 9, 2014 at 10:39 PM, Michal D.  wrote:
> I meant that +/"1 in our fantasy language would be the equivalent of +/&.>
> in J.
>
> Cheers,
>
> Mike
>
> On Tue, Sep 9, 2014 at 8:15 AM, Linda Alvord 
> wrote:
>
>> I thought Michal was indicating at the end of his message that these were
>> the same.
>>
>> >Something like +/"1 x instead of +/&.> x (obviously there's not much
>> >difference here).
>>
>> Linda
>>
>> -Original Message-
>> From: programming-boun...@forums.jsoftware.com [mailto:
>> programming-boun...@forums.jsoftware.com] On Behalf Of Michal D.
>> Sent: Tuesday, September 09, 2014 1:14 AM
>> To: programm...@jsoftware.com
>> Subject: Re: [Jprogramming] Ragged Array Shapes are Trees
>>
>> One can imagine that it's possible for
>>
>>] x =. (<@i."0) 1+i.3
>> +-+---+-+
>> |0|0 1|0 1 2|
>> +-+---+-+
>>
>> to be laid out in memory as [0 0 1 0 1 2] with an additional vector
>> representing the starting point of each rank-1 array [0 1 3 6].  I would be
>> willing to wager a large sum that this is much more computationally
>> efficient than having a representation where each rank-1 array is floating
>> off somewhere in memory [0] [0 1] [0 1 2] with an array of pointers to
>> them.
>>
>> Of course this representation is possible, but somewhat verbose, to do
>> manually in J (http://dl.acm.org/citation.cfm?id=804488).  That's why I'm
>> fantasizing about a language where such a representation would be closer to
>> the core of the language.
>>
>> Something like +/"1 x instead of +/&.> x (obviously there's not much
>> difference here).
>>
>> Like we've both suggested, it may be that boxing with a sufficiently
>> optimized interpreter is the solution.
>>
>> Cheers,
>>
>> Mike
>>
>> On Mon, Sep 8, 2014 at 8:10 AM, Raul Miller  wrote:
>>
>> > What does this mean "shapes extended to support ragged arrays without
>> > boxing"?
>> >
>> > K has ragged arrays without boxing, but K's concept of shape only
>> > applies to the non-ragged prefix dimensions.
>> >
>> > Meanwhile, it seems to me that the guarantee you suggest would be
>> > computationally expensive.
>> >
>> > (Not saying the ideas shouldn't be explored, but I suspect what you
>> > are really after is a more efficient boxing implementation and that
>> > will lead in an entirely different direction.)
>> >
>> > Thanks,
>> >
>> > --
>> > Raul
>> >
>> >
>> > On Mon, Sep 8, 2014 at 11:01 AM, Michal D. 
>> > wrote:
>> > > Thanks Pascal, that's a nice formulation for the 2-level deep case.  It
>> > > breaks down of course for deeper nesting but could serve as a base.
>> > >
>> > > ([:|. $ ;~ $ each) ((i.2 3);(,0)) ; (i. 2 3)
>> > > +-+---+
>> > > |2|+-+---+|
>> > > | ||2|2 3||
>> > > | |+-+---+|
>> > > +-+---+
>> > >
>> > > There's no specific problem I'm trying to solve directly in J at the
>> > > moment.  It's more of a language design problem.  My interest in this
>> is
>> > a
>> > > J like language, but with shapes extended to support ragged arrays
>> > without
>> > > boxing.  Failing that, we could have some optimization guarantees like
>> > 'an
>> > > array of boxes containing equal rank values are allocated
>> contiguously'.
>> > >
>> > > Cheers,
>> > >
>> > > Mike
>> > >
>> > >
>> > >
>> > > On Sat, Sep 6, 2014 at 9:28 AM, 'Pascal Jasmin' via Programming <
>> > > programm...@jsoftware.com> wrote:
>> > >
>> > >> Hi Michal,
>> > >>
>> > >> maybe this is an interesting representation for what you want?
>> > >>
>> > >>([:|. $ ;~ $ each) (i. 2 3) ; (,0) ; 0 1
>> > >> ┌─┬─┐
>> > >> │3│┌───┬─┬─┐│
>> > >> │ ││2 3│1│2││
>> > >> │ │└───┴─┴─┘│
>> > >> └─┴─┘
>> > >>
>> > >>
>> > >>
>> > >> - Original Message -
>> > >> From: Michal

Re: [Jprogramming] zlib huffman coding

2014-09-10 Thread Raul Miller
I think the use of the term "consecutive" rather than "sequential" is telling.

The described algorithm is: compute the huffman code lengths:
   #@>F1 hcodes A1
1 3 7 7 6 6 6 6 6 6 6 2

Then assign ascending huffman codes first in length order and then
within codes of the same length.

Taken literally, that might be something like this:

H=: 4 :0
  L=.#@> x hcodes y
  U=.~.L
  ;<@(({.{.U e.~i.&.<:@{.)<@:+"1-@{.{."1 #:@i.@#)/.~L
)

   ":@>F1 H A1
0
1 1 0
1 1 1 0 0 1 0
1 1 1 0 0 1 1
1 1 1 0 0 0
1 1 1 0 0 1
1 1 1 0 1 0
1 1 1 0 1 1
1 1 1 1 0 0
1 1 1 1 0 1
1 1 1 1 1 0
1 0

But is this correct? Is it actually safe to leave the results like
this - with all codes of the same length being consecutive to each
other?

   F (hcodes -:&:(#@>) H) A
0

No.

So... "consecutive" must refer only to the values used and not their
order within the result.

Perhaps something like this:

deflatecodes=:4 :0
  L=.#@> x hcodes y
  U=.~.L
  R=. ;<@(({.{.U e.~i.&.<:@{.)<@:+"1-@{.{."1 #:@i.@#)/.~L
  R/:;() deflatecodes)  A
1

There should be a better way of doing this, but this should at least
get you started.

Thanks,

-- 
Raul


On Wed, Sep 10, 2014 at 10:45 AM, bill lam  wrote:
> For huffman coding used in zlib:
> https://www.ietf.org/rfc/rfc1951.txt section 3.2.2.
>
>  The Huffman codes used for each alphabet in the "deflate"
>  format have two additional rules:
>
>   * All codes of a given bit length have lexicographically
>   consecutive values, in the same order as the symbols
>   they represent;
>
>   * Shorter codes lexicographically precede longer codes.
> I tried jwiki hcodes in
> I try Roger's essay
> http://www.jsoftware.com/jwiki/Essays/Huffman%20Coding
>
> hc=: 4 : 0
> if. 1=#x do. y
> else. ((i{x),+/j{x) hc (i{y), )
>
> hcodes=: 4 : 0
> assert. x -:&$ y   NB. weights and words have same shape
> assert. (0<:x) *. 1=#$xNB. weights are non-negative
> assert. 1 >: L.y   NB. words are boxed not more than once
> w=. ,&.> y NB. standardized words
> assert. w -: ~.w   NB. words are unique
> t=. 0 {:: x hc w   NB. minimal weight binary tree
> ((< S: 0 t) i. w) { <@(1&=)@; S: 1 {:: t
> )
>
> but the coding produced is malformed for zlib. eg,
> this is what I ran into trouble
>
> f1=: 1 256 17 1 1 9 1
> f2=: 2 1 0 1 255 0 1536
> F=: ,/(f1#f2)
> A=: i.286
>
> F hcodes A
>
> Or a shorter example
>
> A1=: i.12
> F1=: 2 1 0 0 0 0 0 0 0 0 0 1
>
> F1 hcodes A1
>
> Any idea?
>
> --
> regards,
> 
> GPG key 1024D/4434BAB3 2008-08-24
> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Replace one item of a list

2014-09-10 Thread Raul Miller
Product managers, in general, do not make their decisions on technical
grounds, but on popularity grounds.

That means we need to support people generating media - art (images
and image manipulating tools), games (games themselves but also tools
for working with the data used in games), music (sounds, rhythms,
samples, sequencers, ...), video (just reading and writing video
format data would be a big step), writers (outlining tools?), ...

In other words, tools like "plot" are great examples of the sort of
thing we should be working on (and tying into external tools is also
really good). But I think we need to focus more on things created with
J than on the language itself.

Perhaps the right first step would be to make an "art" mailing list,
for people to show off things they have created using J? If our
current population is anything like me, our initial traffic on such a
list might be more doodles and drivel than masterworks and multimedia,
but you have to start somewhere.

Thanks,

-- 
Raul

On Wed, Sep 10, 2014 at 12:59 PM, Dan Bron  wrote:
> Product managers, in general, aren't going to base their decisions on what
> some random internet stranger wrote on an obscure mailing list. More
> likely to influence their decision is the very fact that the primary
> mailing list for the language is obscure.
>
> In other words: if our goal is to get people to use J for serious,
> commercial, purposes, then to borrow (steal) a phrase from Tracy: we need
> to go to them. The absolute best documentation in the history of
> documentation won't matter a bit if no one ever reads it.
>
> That said, once we go to them, we'll have to convince them we have
> something interesting to say.  One way to do that is to tell them,
> straight off, that J is unlike anything they've seen before ("un-C
> yourself, un-FORTRAN yourself...").
>
> And then prove it.
>
> -Dan
>
> PS:  Now you can see why I've taken the tactic I've taken on RosettaCode,
> for example (I am honestly trying to bait people into calling bullshit;
> which is how, incidentally, I've become undisputed champion of Liar's
> Poker around the office.)
>
>
>
> - Original Message ---
>
> Subject: Re: [Jprogramming] Replace one item of a list
>From: Ian Clark 
>Date: Wed, 10 Sep 2014 17:38:21 +0100
>  To: programm...@jsoftware.com
>
> Sorry, Dan -- none of that would work for me if I were a product manager.
> One with some control over which language to choose and to recruit my
> programmers for. Or more like it: which language to avoid. One sight of
> this thread and I'd say "toy language -- my staff will be spending all
> their time fighting the interpreter, not working with it." As I've seen in
> practice with APL. More than once.
>
> Which is sad, because I see J as overcoming many of the problems of APL
> (any vendor's) when used as the development language for a commercial
> product with industrial-strength data. But you have to soak in J a bit
> before you become convinced of that.
>
> It won't have escaped notice that I'm fixated on improving J's uptake via
> documentation.
>
> On Wed, Sep 10, 2014 at 4:41 PM, Dan Bron  wrote:
>
>> When I see a newcomer (not you, Ian, obviously) raise such concerns as "how
>> do I do updates in place?", my typical response to this is:
>>
>> J is a function-level language.  It expresses computations in terms of data
>> flow.  Verbs (functions) are primary; nouns (data) are secondary.
>>
>> STOP THINKING IN TERMS OF UPDATING MUTABLE STATE.
>>
>> 
>>
>> Of course, like many programming languages, a number of optimizations have
>> been made in the background, as you (Ian) and Henry have so carefully
>> enumerated.
>>
>> In-place amendment, where appropriate, is one of these optimizations.  But
>> that's an implementation detail; the problem is in the mindset that gives
>> priority to the question.
>>
>> ---
>>
>> Focus your attention on learning J *as a notation*, as a *language for
>> expressing yourself*, first.  Un-C yourself; un-FORTRAN yourself; un-APL
>> yourself. Let J in.
>>
>> Worry about learning how to make J work, before you worry about how to make
>> J fast.
>>
>> ---
>>
>> And finally, that old chestnut about premature optimizaton.  Get it
>> working, then profile it. Optimize the parts that are observably,
>> empirically, the slowest (perhaps using the list of special code mentioned
>> above).
>>
>> If it's still too slow, complain on the Forums. We're here to help.  One
>> form of help might be, ultimately, adding a new optimization to the
>> language proper, as with Pepe's TCO adverb. But in most cases, that will
>> be overkill, and we'll show you other ways to express yourself.
>>
>> -Dan
>>
>> - Original Message ---
>>
>> Subject: Re: [Jprogramming] Replace one item of a list
>>From: Ian Clark 
>>Date: Wed, 10 Sep 2014 16:18:34 +0100
>>  To: programm...@jsoftware.com
>>
>> >> Then it actually does in-place updating (even though, at face value, J
>> synt

Re: [Jprogramming] Replace one item of a list

2014-09-10 Thread Raul Miller
I do not see a conflict here.

Thanks,

-- 
Raul


On Wed, Sep 10, 2014 at 1:41 PM, Dan Bron  wrote:
> I'd be up for that.  But probably a better medium is the Wiki, as art is
> typically an iterative process?
>
> -Dan
>
> - Original Message ---
>
> Subject: Re: [Jprogramming] Replace one item of a list
>From: Raul Miller 
>Date: Wed, 10 Sep 2014 13:27:51 -0400
>  To: Programming forum 
>
> Product managers, in general, do not make their decisions on technical
> grounds, but on popularity grounds.
>
> That means we need to support people generating media - art (images
> and image manipulating tools), games (games themselves but also tools
> for working with the data used in games), music (sounds, rhythms,
> samples, sequencers, ...), video (just reading and writing video
> format data would be a big step), writers (outlining tools?), ...
>
> In other words, tools like "plot" are great examples of the sort of
> thing we should be working on (and tying into external tools is also
> really good). But I think we need to focus more on things created with
> J than on the language itself.
>
> Perhaps the right first step would be to make an "art" mailing list,
> for people to show off things they have created using J? If our
> current population is anything like me, our initial traffic on such a
> list might be more doodles and drivel than masterworks and multimedia,
> but you have to start somewhere.
>
> Thanks,
>
> --
> Raul
>
> On Wed, Sep 10, 2014 at 12:59 PM, Dan Bron  wrote:
>> Product managers, in general, aren't going to base their decisions on what
>> some random internet stranger wrote on an obscure mailing list. More
>> likely to influence their decision is the very fact that the primary
>> mailing list for the language is obscure.
>>
>> In other words: if our goal is to get people to use J for serious,
>> commercial, purposes, then to borrow (steal) a phrase from Tracy: we need
>> to go to them. The absolute best documentation in the history of
>> documentation won't matter a bit if no one ever reads it.
>>
>> That said, once we go to them, we'll have to convince them we have
>> something interesting to say.  One way to do that is to tell them,
>> straight off, that J is unlike anything they've seen before ("un-C
>> yourself, un-FORTRAN yourself...").
>>
>> And then prove it.
>>
>> -Dan
>>
>> PS:  Now you can see why I've taken the tactic I've taken on RosettaCode,
>> for example (I am honestly trying to bait people into calling bullshit;
>> which is how, incidentally, I've become undisputed champion of Liar's
>> Poker around the office.)
>>
>>
>>
>> - Original Message ---
>>
>> Subject: Re: [Jprogramming] Replace one item of a list
>>From: Ian Clark 
>>Date: Wed, 10 Sep 2014 17:38:21 +0100
>>  To: programm...@jsoftware.com
>>
>> Sorry, Dan -- none of that would work for me if I were a product manager.
>> One with some control over which language to choose and to recruit my
>> programmers for. Or more like it: which language to avoid. One sight of
>> this thread and I'd say "toy language -- my staff will be spending all
>> their time fighting the interpreter, not working with it." As I've seen in
>> practice with APL. More than once.
>>
>> Which is sad, because I see J as overcoming many of the problems of APL
>> (any vendor's) when used as the development language for a commercial
>> product with industrial-strength data. But you have to soak in J a bit
>> before you become convinced of that.
>>
>> It won't have escaped notice that I'm fixated on improving J's uptake via
>> documentation.
>>
>> On Wed, Sep 10, 2014 at 4:41 PM, Dan Bron  wrote:
>>
>>> When I see a newcomer (not you, Ian, obviously) raise such concerns as "how
>>> do I do updates in place?", my typical response to this is:
>>>
>>> J is a function-level language.  It expresses computations in terms of data
>>> flow.  Verbs (functions) are primary; nouns (data) are secondary.
>>>
>>> STOP THINKING IN TERMS OF UPDATING MUTABLE STATE.
>>>
>>> 
>>>
>>> Of course, like many programming languages, a number of optimizations have
>>> been made in the background, as you (Ian) and Henry have so carefully
>>> enumerated.
>>>
>>> In-place amendment, where appropriate, is one of these optimizations.  But
>>> that&

Re: [Jprogramming] zlib huffman coding

2014-09-10 Thread Raul Miller
Oops, sorry about that.

Try it this way:

deflatecodes2=:4 :0
  L=. #@> x hcodes y
  U=. 0,~.L
  R=. ;<@(({. >./@(>#])&U #1:)@{. <@:+"1-@{.{."1 #:@i.@#)/.~L
  R/:;(F1 deflatecodes2 A1
0
1 1 0
1 1 1 1 1 1 0
1 1 1 1 1 1 1
1 1 1 0 0 0
1 1 1 0 0 1
1 1 1 0 1 0
1 1 1 0 1 1
1 1 1 1 0 0
1 1 1 1 0 1
1 1 1 1 1 0
1 0

Thanks,

-- 
Raul


On Wed, Sep 10, 2014 at 7:26 PM, bill lam  wrote:
> for zlib, all huffman code of the same bit length are in sequential,
> starting with a code an 0 bit in the end (even number), and no gaps in the
> block (consecutive). the symbols of these block represented are sequential
> but not consecutive (possibly gaps). So the zlib huffman code is slightly
> less efficient than the original huffman code but the advantage is simpler
> to store the table, just the bits used. section 3.2.6 gives an example of
> such table.
>
> deflatecodes can satisfy the 2 rules _but_ its result is invalid because
> huffman code is a prefix coding.
>
>,.F1 ( deflatecodes)  A1
> ┌─┐
> │0│
> ├─┤
> │1 1 0│
> ├─┤
> │1 1 1 0 0 1 0│
> ├─┤
> │1 1 1 0 0 1 1│
> ├─┤
> │1 1 1 0 0 0  │
> ├─┤
> │1 1 1 0 0 1  │
> ├─┤
> │1 1 1 0 1 0  │
> ├─┤
> │1 1 1 0 1 1  │
> ├─┤
> │1 1 1 1 0 0  │
> ├─┤
> │1 1 1 1 0 1  │
> ├─┤
> │1 1 1 1 1 0  │
> ├─┤
> │1 0  │
> └─┘
>   7 bit 1110010 is a prefix of 6 bit 111001 and this is illegal.
> Instead 7 bit code block should start with
> #.inv 2b11100 +  7
> 1 1 1 1 1 1 0
> because there are 6 symbols in the 6 bit code.  (algorithm given in section
> 3.2.2).
>
> Any idea to fix deflatecodes so that it can give valid huffman codes?
> Thanks.
> On Sep 11, 2014 1:01 AM, "Raul Miller"  wrote:
>
>> I think the use of the term "consecutive" rather than "sequential" is
>> telling.
>>
>> The described algorithm is: compute the huffman code lengths:
>>#@>F1 hcodes A1
>> 1 3 7 7 6 6 6 6 6 6 6 2
>>
>> Then assign ascending huffman codes first in length order and then
>> within codes of the same length.
>>
>> Taken literally, that might be something like this:
>>
>> H=: 4 :0
>>   L=.#@> x hcodes y
>>   U=.~.L
>>   ;<@(({.{.U e.~i.&.<:@{.)<@:+"1-@{.{."1 #:@i.@#)/.~L
>> )
>>
>>":@>F1 H A1
>> 0
>> 1 1 0
>> 1 1 1 0 0 1 0
>> 1 1 1 0 0 1 1
>> 1 1 1 0 0 0
>> 1 1 1 0 0 1
>> 1 1 1 0 1 0
>> 1 1 1 0 1 1
>> 1 1 1 1 0 0
>> 1 1 1 1 0 1
>> 1 1 1 1 1 0
>> 1 0
>>
>> But is this correct? Is it actually safe to leave the results like
>> this - with all codes of the same length being consecutive to each
>> other?
>>
>>F (hcodes -:&:(#@>) H) A
>> 0
>>
>> No.
>>
>> So... "consecutive" must refer only to the values used and not their
>> order within the result.
>>
>> Perhaps something like this:
>>
>> deflatecodes=:4 :0
>>   L=.#@> x hcodes y
>>   U=.~.L
>>   R=. ;<@(({.{.U e.~i.&.<:@{.)<@:+"1-@{.{."1 #:@i.@#)/.~L
>>   R/:;(> )
>>
>>F (hcodes -:&:(#@>) deflatecodes)  A
>> 1
>>
>> There should be a better way of doing this, but this should at least
>> get you started.
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Wed, Sep 10, 2014 at 10:45 AM, bill lam  wrote:
>> > For huffman coding used in zlib:
>> > https://www.ietf.org/rfc/rfc1951.txt section 3.2.2.
>> >
>> >  The Huffman codes used for each alphabet in the "deflate"
>> >  format have two additional rules:
>> >
>> >   * All codes of a given bit length have lexicographically
>> >   consecutive values, in the same order as the symbols
>> >   they represent;
>> >
>> >   * Shorter codes lexicographically precede longer codes.
>> > I tried jwiki hcodes in
>> > I try Roger's essay
>> > http://www.jsoftware.com/jwiki/Essays/Huffman%20Coding
>> >
>> > hc=: 4 : 0
>> > if. 1=#x do. y
>> > else. ((i{x),+/j{x) hc (i{y),> > )
>> >
>> > hcodes=: 4 : 0
>> > assert. x -:&$ y   NB. weights and words have same shape
>> > assert. (0<:x) *. 1=#$xNB. weights are non-negative
>> > assert. 1 >: L.y   NB. words are boxed not more than once
>> > w=. ,&.> y  

Re: [Jprogramming] zlib huffman coding

2014-09-10 Thread Raul Miller
I agree that there should not be any 2s.

However, I think this means that there's something wrong with the
description of the algorithm, or at least my understanding of it.

I'll need some time to digest this.

Thanks,

-- 
Raul

On Wed, Sep 10, 2014 at 9:39 PM, bill lam  wrote:
> pardon me of forgetting telling another cavaet.
> zlib huffman code is suboptimal so that bit length of code
> for each symbol can be longer than that in classic huffman.
> eg in my orignal data.
>
>10{. ":@>F deflatecodes2 A
> 1 1 0 0 0 0 0 0 0 0
> 1 1 1 1 1 1 1 1 1 1 0
> 1 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 2 0
> 1 1 1 1 1 1 1 1 1 2 1
> 1 1 1 1 1 1 1 1 2 1 0
> 1 1 0 0 0 0 0 0 0 1
> 1 1 0 0 0 0 0 0 1 0
> 1 1 0 0 0 0 0 0 1 1
> 1 1 0 0 0 0 0 1 0 0
>
> there shouldn't be any 2's.  It needs to increase bit length of
> some code.
>
> Ср, 10 сен 2014, Raul Miller написал(а):
>> Oops, sorry about that.
>>
>> Try it this way:
>>
>> deflatecodes2=:4 :0
>>   L=. #@> x hcodes y
>>   U=. 0,~.L
>>   R=. ;<@(({. >./@(>#])&U #1:)@{. <@:+"1-@{.{."1 #:@i.@#)/.~L
>>   R/:;(> )
>>
>>":@>F1 deflatecodes2 A1
>> 0
>> 1 1 0
>> 1 1 1 1 1 1 0
>> 1 1 1 1 1 1 1
>> 1 1 1 0 0 0
>> 1 1 1 0 0 1
>> 1 1 1 0 1 0
>> 1 1 1 0 1 1
>> 1 1 1 1 0 0
>> 1 1 1 1 0 1
>> 1 1 1 1 1 0
>> 1 0
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Wed, Sep 10, 2014 at 7:26 PM, bill lam  wrote:
>> > for zlib, all huffman code of the same bit length are in sequential,
>> > starting with a code an 0 bit in the end (even number), and no gaps in the
>> > block (consecutive). the symbols of these block represented are sequential
>> > but not consecutive (possibly gaps). So the zlib huffman code is slightly
>> > less efficient than the original huffman code but the advantage is simpler
>> > to store the table, just the bits used. section 3.2.6 gives an example of
>> > such table.
>> >
>> > deflatecodes can satisfy the 2 rules _but_ its result is invalid because
>> > huffman code is a prefix coding.
>> >
>> >,.F1 ( deflatecodes)  A1
>> > ┌─┐
>> > │0│
>> > ├─┤
>> > │1 1 0│
>> > ├─┤
>> > │1 1 1 0 0 1 0│
>> > ├─┤
>> > │1 1 1 0 0 1 1│
>> > ├─┤
>> > │1 1 1 0 0 0  │
>> > ├─┤
>> > │1 1 1 0 0 1  │
>> > ├─┤
>> > │1 1 1 0 1 0  │
>> > ├─┤
>> > │1 1 1 0 1 1  │
>> > ├─┤
>> > │1 1 1 1 0 0  │
>> > ├─┤
>> > │1 1 1 1 0 1  │
>> > ├─┤
>> > │1 1 1 1 1 0  │
>> > ├─┤
>> > │1 0  │
>> > └─┘
>> >   7 bit 1110010 is a prefix of 6 bit 111001 and this is illegal.
>> > Instead 7 bit code block should start with
>> > #.inv 2b11100 +  7
>> > 1 1 1 1 1 1 0
>> > because there are 6 symbols in the 6 bit code.  (algorithm given in section
>> > 3.2.2).
>> >
>> > Any idea to fix deflatecodes so that it can give valid huffman codes?
>> > Thanks.
>> > On Sep 11, 2014 1:01 AM, "Raul Miller"  wrote:
>> >
>> >> I think the use of the term "consecutive" rather than "sequential" is
>> >> telling.
>> >>
>> >> The described algorithm is: compute the huffman code lengths:
>> >>#@>F1 hcodes A1
>> >> 1 3 7 7 6 6 6 6 6 6 6 2
>> >>
>> >> Then assign ascending huffman codes first in length order and then
>> >> within codes of the same length.
>> >>
>> >> Taken literally, that might be something like this:
>> >>
>> >> H=: 4 :0
>> >>   L=.#@> x hcodes y
>> >>   U=.~.L
>> >>   ;<@(({.{.U e.~i.&.<:@{.)<@:+"1-@{.{."1 #:@i.@#)/.~L
>> >> )
>> >>
>> >>":@>F1 H A1
>> >> 0
>> >> 1 1 0
>> >> 1 1 1 0 0 1 0
>> >> 1 1 1 0 0 1 1
>> >> 1 1 1 0 0 0
>> >> 1 1 1 0 0 1
>> >> 1 1 1 0 1 0
>> >> 1 1 1 0 1 1
>> >> 1 1 1 1 0 0
>> >> 1 1 1 1 0 1
>> >> 1 1 1 1 1 0
>> >> 1 0
>> >>
>> >> But is this correct? Is it actually safe to leave the results like
>> >> this - wit

Re: [Jprogramming] zlib huffman coding

2014-09-10 Thread Raul Miller
Something is wrong here:

   $bits
286
   (0=bits)-:0=F1
0
   +/0=F1
9
   +/0=bits
26

0 bits should mean that that symbol is not represented.

But there are only 9 such symbols in F1.

-- 
Raul

On Wed, Sep 10, 2014 at 11:09 PM, bill lam  wrote:
> I guess the description of the algorithm itself is correct, but
> it does not mention how to get the bits of each symbol. The bit
> lengths for classic and zlib huffman can be different.
>
> for testing, the bits for A from libz.so are
>
>":&>_10<\bits
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 11 11 10 10 10 10 11
> 11 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 10 10 10
> 10 10 10 10 10 10 10 0 0 0
> 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 10 2 0 0 0 0
> 0 0 0 0 0 1
>
> this is the huffman dictionary stored in zlib stream and the actual
> huffman codes are computed using the algorithm mentioned during decoding.
>
> Ср, 10 сен 2014, Raul Miller написал(а):
>> I agree that there should not be any 2s.
>>
>> However, I think this means that there's something wrong with the
>> description of the algorithm, or at least my understanding of it.
>>
>> I'll need some time to digest this.
>>
>> Thanks,
>>
>> --
>> Raul
>>
>> On Wed, Sep 10, 2014 at 9:39 PM, bill lam  wrote:
>> > pardon me of forgetting telling another cavaet.
>> > zlib huffman code is suboptimal so that bit length of code
>> > for each symbol can be longer than that in classic huffman.
>> > eg in my orignal data.
>> >
>> >10{. ":@>F deflatecodes2 A
>> > 1 1 0 0 0 0 0 0 0 0
>> > 1 1 1 1 1 1 1 1 1 1 0
>> > 1 1 1 1 1 1 1 1 1 1 1
>> > 1 1 1 1 1 1 1 1 1 2 0
>> > 1 1 1 1 1 1 1 1 1 2 1
>> > 1 1 1 1 1 1 1 1 2 1 0
>> > 1 1 0 0 0 0 0 0 0 1
>> > 1 1 0 0 0 0 0 0 1 0
>> > 1 1 0 0 0 0 0 0 1 1
>> > 1 1 0 0 0 0 0 1 0 0
>> >
>> > there shouldn't be any 2's.  It needs to increase bit length of
>> > some code.
>> >
>> > Ср, 10 сен 2014, Raul Miller написал(а):
>> >> Oops, sorry about that.
>> >>
>> >> Try it this way:
>> >>
>> >> deflatecodes2=:4 :0
>> >>   L=. #@> x hcodes y
>> >>   U=. 0,~.L
>> >>   R=. ;<@(({. >./@(>#])&U #1:)@{. <@:+"1-@{.{."1 #:@i.@#)/.~L
>> >>   R/:;(> >> )
>> >>
>> >>":@>F1 deflatecodes2 A1
>> >> 0
>> >> 1 1 0
>> >> 1 1 1 1 1 1 0
>> >> 1 1 1 1 1 1 1
>> >> 1 1 1 0 0 0
>> >> 1 1 1 0 0 1
>> >> 1 1 1 0 1 0
>> >> 1 1 1 0 1 1
>> >> 1 1 1 1 0 0
>> >> 1 1 1 1 0 1
>> >> 1 1 1 1 1 0
>> >> 1 0
>> >>
>> >> Thanks,
>> >>
>> >> --
>> >> Raul
>> >>
>> >>
>> >> On Wed, Sep 10, 2014 at 7:26 PM, bill lam  wrote:
>> >> > for zlib, all huffman code of the same bit length are in sequential,
>> >> > starting with a code an 0 bit in the end (even number), and no gaps in 
>> >> > the
>> >> > block (consecutive). the symbols of these block represented are 
>> >> > sequential
>> >> > but not consecutive (possibly gaps). So the zlib huffman code is 
>> >> > slightly
>> >> > less efficient than the original huffman code but the advantage is 
>> >> > simpler
>> >> > to store the table, just the bits used. section 3.2.6 gives an example 
>> >> > of
>> >> > such table.
>> >> >
>> >> > deflatecodes can satisfy the 2 rules _but_ its result is invalid because
>> >> > huffman code is a prefix coding.
>> >> >
>> >> >,.F1 ( deflatecodes)  A1
>> >> > ┌

Re: [Jprogramming] zlib huffman coding

2014-09-10 Thread Raul Miller
Ah, good point.

 Here's another thing:

   +/ bits < #@> F hcodes A
31

In some cases the deflate codes have fewer bits than huffman coding.

So the problem is finding the algorithm that was used to define bits - it's
not the huffman coding algorithm.

I guess I need to spend some time reading rfc 1951.

Thanks,

-- 
Raul

On Wed, Sep 10, 2014 at 11:41 PM, bill lam  wrote:

> It refered to A and F (not A1 and F1) in my first email.
>
> I sent you an email off-list that included attachments.
>
>
> Ср, 10 сен 2014, Raul Miller написал(а):
> > Something is wrong here:
> >
> >$bits
> > 286
> >(0=bits)-:0=F1
> > 0
> >+/0=F1
> > 9
> >+/0=bits
> > 26
> >
> > 0 bits should mean that that symbol is not represented.
> >
> > But there are only 9 such symbols in F1.
> >
> > --
> > Raul
> >
> > On Wed, Sep 10, 2014 at 11:09 PM, bill lam  wrote:
> > > I guess the description of the algorithm itself is correct, but
> > > it does not mention how to get the bits of each symbol. The bit
> > > lengths for classic and zlib huffman can be different.
> > >
> > > for testing, the bits for A from libz.so are
> > >
> > >":&>_10<\bits
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 11 11 10 10 10 10 11
> > > 11 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 10 10 10
> > > 10 10 10 10 10 10 10 0 0 0
> > > 0 0 0 0 0 0 0 0 0 0
> > > 0 0 0 0 10 2 0 0 0 0
> > > 0 0 0 0 0 1
> > >
> > > this is the huffman dictionary stored in zlib stream and the actual
> > > huffman codes are computed using the algorithm mentioned during
> decoding.
> > >
> > > Ср, 10 сен 2014, Raul Miller написал(а):
> > >> I agree that there should not be any 2s.
> > >>
> > >> However, I think this means that there's something wrong with the
> > >> description of the algorithm, or at least my understanding of it.
> > >>
> > >> I'll need some time to digest this.
> > >>
> > >> Thanks,
> > >>
> > >> --
> > >> Raul
> > >>
> > >> On Wed, Sep 10, 2014 at 9:39 PM, bill lam 
> wrote:
> > >> > pardon me of forgetting telling another cavaet.
> > >> > zlib huffman code is suboptimal so that bit length of code
> > >> > for each symbol can be longer than that in classic huffman.
> > >> > eg in my orignal data.
> > >> >
> > >> >10{. ":@>F deflatecodes2 A
> > >> > 1 1 0 0 0 0 0 0 0 0
> > >> > 1 1 1 1 1 1 1 1 1 1 0
> > >> > 1 1 1 1 1 1 1 1 1 1 1
> > >> > 1 1 1 1 1 1 1 1 1 2 0
> > >> > 1 1 1 1 1 1 1 1 1 2 1
> > >> > 1 1 1 1 1 1 1 1 2 1 0
> > >> > 1 1 0 0 0 0 0 0 0 1
> > >> > 1 1 0 0 0 0 0 0 1 0
> > >> > 1 1 0 0 0 0 0 0 1 1
> > >> > 1 1 0 0 0 0 0 1 0 0
> > >> >
> > >> > there shouldn't be any 2's.  It needs to increase bit length of
> > >> > some code.
> > >> >
> > >> > Ср, 10 сен 2014, Raul Miller написал(а):
> > >> >> Oops, sorry about that.
> > >> >>
> > >> >> Try it this way:
> > >> >>
> > >> >> deflatecodes2=:4 :0
> > >> >>   L=. #@> x hcodes y
> > >> >>   U=. 0,~.L
> > >> >>   R=. ;<@(({. >./@(>#])&U #1:)@{. <@:+"1-@{.{."1 #:@i.@#)/.~L
> > >> >>   R/:;( > >

Re: [Jprogramming] Extend/reduce matrix dimensions

2014-09-11 Thread Raul Miller
Here are some perhaps relevant examples:

   1 1 0 1 #inv (3 3$ 0)
0 0 0
0 0 0
0 0 0
0 0 0
   1 1 0 1 #inv!.1 (3 3$ 0)
0 0 0
0 0 0
1 1 1
0 0 0
   1 1 0 1 #inv!.1"1 (3 3$ 0)
0 0 1 0
0 0 1 0
0 0 1 0
   1 1 0 1 #inv!.1"1 (1 1 0 1) #inv!.1 (3 3$ 0)
0 0 1 0
0 0 1 0
1 1 1 1
0 0 1 0
   1 1 0 1 # 1 1 0 1 #inv!.1"1 (1 1 0 1) #inv!.1 (3 3$ 0)
0 0 1 0
0 0 1 0
0 0 1 0
   1 1 0 1 #("1) 1 1 0 1 # 1 1 0 1 #inv!.1"1 (1 1 0 1) #inv!.1 (3 3$ 0)
0 0 0
0 0 0
0 0 0
   (i.3) 2} 1 1 0 1 #inv (3 3$0)
0 0 0
0 0 0
0 1 2
0 0 0
   (i.4) 2}"0 1 (1 1 0 1) #inv"1 (i.3) 2} 1 1 0 1 #inv (3 3$0)
0 0 0 0
0 0 1 0
0 1 2 2
0 0 3 0
   (i.4) 2}"0 1 (1 1 0 1) #inv"1 (0 1 3) 2} 1 1 0 1 #inv (3 3$0)
0 0 0 0
0 0 1 0
0 1 2 3
0 0 3 0

The whole #inv thing is a bit quirky but was quite deliberate. This was a
primitive in APL, but the syntax was ... strange. Rather than trying to
find a special symbol for this operation, Iverson put it on #inv (since -
logically speaking - it's the inverse of #).

Thanks,

-- 
Raul


On Thu, Sep 11, 2014 at 5:21 AM, Sebastian  wrote:

> Hi,
>
> I know the verbs , ,. ,: to add rows, columns and dimensions to matrices.
> It is easy to add these to begin or the end of the corrosponding dimension,
> but what is to do, if I want to add one row/column in the middle of a
> matrix? Is the only way to slice the matrix in two pieces and join them
> with the new row/column?
>
> A few examples:
>
> Initial situation:
>
> 3 3 $ 0
> 0 0 0
>
> 0 0 0
>
> 0 0 0
>
>
> add column somewhere to the middle:
>
> 0 0 1 0
>
> 0 0 1 0
>
> 0 0 1 0
>
>
>
> add row somewhere to the middle:
>
> 0 0 1 0
>
> 0 0 1 0
>
> 1 1 1 1
>
> 0 0 1 0
>
>
> remove the added column:
>
> 0 0 0
>
> 0 0 0
>
> 1 1 1
>
> 0 0 0
>
>
>
> and the row:
>
>
>
> 0 0 0
>
> 0 0 0
>
> 0 0 0
>
>
>
> Can anyone help me with this?
>
>
>
> Regards
>
> Sebastian
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] zlib huffman coding

2014-09-11 Thread Raul Miller
Here's a corrected implementation of find_codes

bl_count=:3 :0
  0,}.<:#/.~(,~ [: i. 1 + >./)y
)

start_vals=: +:@+/\.&.|.@}:@,~&0

find_codes=:3 :0
 b=. bl_count y
 v=. start_vals b
 n=. /:~ ~.y-.0
 o=. ;({./.~ /:~ (n (([#2:) #: ])&.> (*b)#v+&.>i.&.>b
 c /: o
)

Argument is the same as for huffman_codes.

If you prefer the 0&huffman_codes result, it's like this:

def_code=:3 :0
 b=. bl_count y
 v=. start_vals b
 n=. /:~ ~.y-.0
 o=. ;({./.~ /:~ ((*b)#v+&.>i.&.>b
 (,. i.@#)c /: o
)

Thanks,

-- 
Raul

On Thu, Sep 11, 2014 at 6:32 AM, bill lam  wrote:

> oops, I made lots of typo.
>
> ..  without prior knowing 
> On Sep 11, 2014 3:45 PM, "bill lam"  wrote:
>
> > the frequencies (guessing from bit lengths) should be something like 2 3
> 1
> > 1
> >   (2 3 1 1) hcodes 'ABCD'
> >
> > the hard part is the inverse problem: how to get the huffman code with
> > prior knowing the bits for each symbol.  Your pointer to the putty
> > fork looks like helpful.  The comment is in lines 861 to 914, the code
> > itself in line 915 to 964. Do you know how to express it in J?
> > Thanks.
> >
> > On Thu, Sep 11, 2014 at 2:57 PM, Joe Bogner  wrote:
> > > Here a few other links ... after reading through the RFC. Not sure if
> > > they help, but just sharing from my own research into assisting on
> > > this topic
> > >
> > > https://github.com/evegard/pngview/blob/master/huffman.c#L54
> > >
> > > And a fork of the putty version with dynamic huffman coding:
> > >
> >
> http://rc.quest.com/viewvc/putty/trunk/halibut/deflate.c?diff_format=s&revision=2&view=markup
> > >
> > > Or just generally googling some of the code from the RFC:
> > >
> >
> https://www.google.com/search?q=next_code%5Blen%5D%2B%2B%3B&oq=next_code%5Blen%5D%2B%2B%3B&aqs=chrome..69i57.387j0j7&sourceid=chrome&es_sm=93&ie=UTF-8#q=next_code%5Blen%5D%2B%2B%3B&start=20
> > >
> > >
> > > Using the code from
> > > http://www.jsoftware.com/jwiki/Essays/Huffman%20Coding, I got stuck
> > > trying to match a simple example to the binary tree in the RFC:
> > >
> > > From the RFC:
> > >
> > >   /\  SymbolCode
> > >  0  1 --
> > > /\A  00
> > >/\ B   B   1
> > >   0  1C 011
> > >  /\   D 010
> > > A /\
> > >  0  1
> > > /\
> > >D  C
> > >
> > >
> > >
> > >(4#1) hcodes 'ABCD'
> > > ┌───┬───┬───┬───┐
> > > │0 0│0 1│1 0│1 1│
> > > └───┴───┴───┴───┘
> > >
> > > Per the RFC, ideally that should match this? '00';'1';'011';'010'
> > >
> > >
> > > From there, it seems like a pretty straightforward exercise to
> > > transliterate the C code from the RFC into J code to recode the
> > > example to:
> > >
> > >
> > > Symbol  Code
> > > --  
> > > A   10
> > > B   0
> > > C   110
> > > D   111
> > >
> > >
> > > I would probably start with a looping construct like what's in the RFC
> > > and then figure out a more J way to do it, but first I would need to
> > > figure out how to create the binary tree in that initial format.
> > >
> > > On Wed, Sep 10, 2014 at 7:41 PM, bill lam  wrote:
> > >> Thanks Joe,
> > >> putty only use zlib static huffman for encoding so that it does not
> > build
> > >> any huffman dictionary table.
> > >>
> > >> The zlib static huffman code does not care about individual symbol's
> > >> frequency, it just encode 0 to 286 into bits, see section 3.2.6.
> > >>  On Sep 11, 2014 1:26 AM, "Joe Bogner"  wrote:
> > >>
> > >>> You've already likely considered this, but if it were me I would
> > compare
> > >>> results to a working implementation. The one from putty seems pretty
> > clean
> > >>> and standalone:
> > >>>
> >
> https://ra

Re: [Jprogramming] Extend/reduce matrix dimensions

2014-09-11 Thread Raul Miller
Here's an example of how I frequently use non-truth-valued #

   9!:7]9 1 1#'+|-'

Thanks,

-- 
Raul

On Thu, Sep 11, 2014 at 6:49 AM, Dan Bron  wrote:

> Note also that you can use plain, uninverted # to expand arguments:
>
>1 1j1 1 (#!.1) 3 3 $ 0
> 0 0 0
> 0 0 0
> 1 1 1
> 0 0 0
>1 1j1 1 (#!.1"1) 3 3 $ 0
> 0 0 1 0
> 0 0 1 0
> 0 0 1 0
>
>
> Which approach you pick often depends on whether it's easier for you to
> express your expansion vector with length N (complex numbers) or N+1
> (boolean numbers).
>
> -Dan
>
> This is worth remembering as well, though I rarely see it used:
>
>1 2 1 # i. 3 3
> 0 1 2
> 3 4 5
> 3 4 5
> 6 7 8
>
> Please excuse typos; sent from a phone.
>
> > On Sep 11, 2014, at 5:32 AM, Raul Miller  wrote:
> >
> > Here are some perhaps relevant examples:
> >
> >   1 1 0 1 #inv (3 3$ 0)
> > 0 0 0
> > 0 0 0
> > 0 0 0
> > 0 0 0
> >   1 1 0 1 #inv!.1 (3 3$ 0)
> > 0 0 0
> > 0 0 0
> > 1 1 1
> > 0 0 0
> >   1 1 0 1 #inv!.1"1 (3 3$ 0)
> > 0 0 1 0
> > 0 0 1 0
> > 0 0 1 0
> >   1 1 0 1 #inv!.1"1 (1 1 0 1) #inv!.1 (3 3$ 0)
> > 0 0 1 0
> > 0 0 1 0
> > 1 1 1 1
> > 0 0 1 0
> >   1 1 0 1 # 1 1 0 1 #inv!.1"1 (1 1 0 1) #inv!.1 (3 3$ 0)
> > 0 0 1 0
> > 0 0 1 0
> > 0 0 1 0
> >   1 1 0 1 #("1) 1 1 0 1 # 1 1 0 1 #inv!.1"1 (1 1 0 1) #inv!.1 (3 3$ 0)
> > 0 0 0
> > 0 0 0
> > 0 0 0
> >   (i.3) 2} 1 1 0 1 #inv (3 3$0)
> > 0 0 0
> > 0 0 0
> > 0 1 2
> > 0 0 0
> >   (i.4) 2}"0 1 (1 1 0 1) #inv"1 (i.3) 2} 1 1 0 1 #inv (3 3$0)
> > 0 0 0 0
> > 0 0 1 0
> > 0 1 2 2
> > 0 0 3 0
> >   (i.4) 2}"0 1 (1 1 0 1) #inv"1 (0 1 3) 2} 1 1 0 1 #inv (3 3$0)
> > 0 0 0 0
> > 0 0 1 0
> > 0 1 2 3
> > 0 0 3 0
> >
> > The whole #inv thing is a bit quirky but was quite deliberate. This was a
> > primitive in APL, but the syntax was ... strange. Rather than trying to
> > find a special symbol for this operation, Iverson put it on #inv (since -
> > logically speaking - it's the inverse of #).
> >
> > Thanks,
> >
> > --
> > Raul
> >
> >
> >> On Thu, Sep 11, 2014 at 5:21 AM, Sebastian  wrote:
> >>
> >> Hi,
> >>
> >> I know the verbs , ,. ,: to add rows, columns and dimensions to
> matrices.
> >> It is easy to add these to begin or the end of the corrosponding
> dimension,
> >> but what is to do, if I want to add one row/column in the middle of a
> >> matrix? Is the only way to slice the matrix in two pieces and join them
> >> with the new row/column?
> >>
> >> A few examples:
> >>
> >> Initial situation:
> >>
> >> 3 3 $ 0
> >> 0 0 0
> >>
> >> 0 0 0
> >>
> >> 0 0 0
> >>
> >>
> >> add column somewhere to the middle:
> >>
> >> 0 0 1 0
> >>
> >> 0 0 1 0
> >>
> >> 0 0 1 0
> >>
> >>
> >>
> >> add row somewhere to the middle:
> >>
> >> 0 0 1 0
> >>
> >> 0 0 1 0
> >>
> >> 1 1 1 1
> >>
> >> 0 0 1 0
> >>
> >>
> >> remove the added column:
> >>
> >> 0 0 0
> >>
> >> 0 0 0
> >>
> >> 1 1 1
> >>
> >> 0 0 0
> >>
> >>
> >>
> >> and the row:
> >>
> >>
> >>
> >> 0 0 0
> >>
> >> 0 0 0
> >>
> >> 0 0 0
> >>
> >>
> >>
> >> Can anyone help me with this?
> >>
> >>
> >>
> >> Regards
> >>
> >> Sebastian
> >> --
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Question on rank conjunction's behavior regarding "unexpected" vector transposition

2014-09-11 Thread Raul Miller
The important thing to understand is that Rank is a count of dimensions.

So u"1 means that the arguments to u have (at most) 1 dimension, and u"2
means that the arguments to u have (at most) 2 dimensions. Any 'extra'
dimensions get treated independently.

See also: https://en.wikipedia.org/wiki/Rank_(J_programming_language)

Thanks,

-- 
Raul


On Thu, Sep 11, 2014 at 10:59 AM, George Dallas 
wrote:

> Let’s say we have a rank 3 array A like so:
>
>
>
>]A=.i.2 4 7
>
>  0  1  2  3  4  5  6
>
>  7  8  9 10 11 12 13
>
> 14 15 16 17 18 19 20
>
> 21 22 23 24 25 26 27
>
>
>
> 28 29 30 31 32 33 34
>
> 35 36 37 38 39 40 41
>
> 42 43 44 45 46 47 48
>
> 49 50 51 52 53 54 55
>
>
>
> And we would like to add the rows. The rank conjunction along the second
> dimension seems to work fine in this case.
>
>
>
>+/"2 A
>
>  42  46  50  54  58  62  66
>
> 154 158 162 166 170 174 178
>
>
>
> Now let’s say we’d like to add the columns. The rank conjunction along the
> first dimension is employed in this case to produce the result.
>
>
>
>+/"1 A
>
>  21  70 119 168
>
> 217 266 315 364
>
>
>
> It is this result where I, being a J novice, perceive that an unexpected
> transposition has taken place. I’ll explain what formed my expectations.
> Coming from a Matlab background I’m used to expect the results in a certain
> spatial location. For example, if I wanted to replicate the same results in
> Matlab I would do something like the following with A being a 4 by 7 by 2
> array (as opposed to a 2 by 4 by 7 in J, but this is a very minor
> difference and one can adjust to it easily).
>
>
>
> >> A
>
> A(:,:,1) =
>
>  0 1 2 3 4 5 6
>
>  7 8 910111213
>
> 14151617181920
>
> 21222324252627
>
> A(:,:,2) =
>
> 28293031323334
>
> 35363738394041
>
> 42434445464748
>
> 49505152535455
>
>
>
> >> sum(A,1)
>
> ans(:,:,1) =
>
> 42465054586266
>
> ans(:,:,2) =
>
>154   158   162   166   170   174   178
>
>
>
> >> sum(A,2)
>
> ans(:,:,1) =
>
> 21
>
> 70
>
>119
>
>168
>
> ans(:,:,2) =
>
>217
>
>266
>
>315
>
>364
>
>
>
> So Matlab’s sum(A,1) corresponds to J’s +/”2 A, but Matlab’s sum(A,2)
> corresponds to a visually transposed form of J’s +/”1 A. In other words,
> the shape of the result of adding columns in Matlab carries a spatial
> resemblance to performing the addition of the columns of A on a chalkboard
> and writing the result in a vertical manner for each successive row.
>
>
>
> I suspect there are good reasons for this behavior in J that allow for easy
> scaling of the results in higher dimensions. I think my fear is that this
> behavior might lead me to erroneous indexing due to not having the proper
> visualization of the results. For example in Matlab I could find result of
> the sum of the columns of A for the third row of the first 2D slice at the
> position (3,1,1) of the result of sum(A,2). Whereas I’m not sure about the
> proper way of indexing on the results of +/”1 A.
>
>
>
> I have observed this behavior elsewhere in J as well. For example using the
> dyad ,. (stitch) on i.5 and 1+i.5, seems to first transpose the row vectors
> and then appending to the right, whereas I was expecting the row vector 0 1
> 2 3 4 1 2 3 4 5 as output.
>
>
>
>i.5
>
> 0 1 2 3 4
>
>1+i.5
>
> 1 2 3 4 5
>
>(i.5),.(1+i.5)
>
> 0 1
>
> 1 2
>
> 2 3
>
> 3 4
>
> 4 5
>
>
>
> My question to the J community then is with regards to the appropriate way
> to think about arrays in J so that I can correctly anticipate vector
> transposition when applying the rank conjunction and how to properly index
> on its result.
>
>
>
> Thank you,
>
> George
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Replace one item of a list

2014-09-11 Thread Raul Miller
On Thu, Sep 11, 2014 at 1:02 PM, Jose Mario Quintana
 wrote:
> My only question is: Does the Dictionary support this behavior?

Yes, it does.

Thanks,

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


Re: [Jprogramming] zlib huffman coding

2014-09-11 Thread Raul Miller
 [73,'1001001'],
>>> > [74,'1001010'],
>>> > [75,'1001011'],
>>> > [76,'1001100'],
>>> > [77,'1001101'],
>>> > [78,'1001110'],
>>> > [79,'100'],
>>> > [80,'101'],
>>> > [81,'1010001'],
>>> > [82,'1010010'],
>>> > [83,'1010011'],
>>> > [84,'1010100'],
>>> > [85,'1010101'],
>>> > [86,'1010110'],
>>> > [87,'1010111'],
>>> > [88,'1011000'],
>>> > [89,'1011001'],
>>> > [90,'1011010']].sort(function(x,y) { return x[1] - y[1] }))
>>> >
>>> > "[[65,"101"],[66,"110"],[67,"111"],[68,"1000100"],[69,"1000101"],[70,"1000110"],[71,"1000111"],[72,"1001000"],[73,"1001001"],[74,"1001010"],[75,"1001011"],[76,"1001100"],[77,"1001101"],[78,"1001110"],[79,"100"],[80,"101"],[81,"1010001"],[82,"1010010"],[83,"1010011"],[84,"1010100"],[85,"1010101"],[86,"1010110"],[87,"1010111"],[88,"1011000"],[89,"1011001"],[90,"1011010"]]"
>>> >
>>> > All the values are sorted correctly.
>>> >
>>> > Here it is with the same ABCD example:
>>> >
>>> > var pako = require('pako');
>>> > var binaryString = pako.deflate('ABCD', { to: 'string' });
>>> > console.log(binaryString);
>>> > var restored = pako.inflate(binaryString, { to: 'string' });
>>> > console.log(restored);
>>> >
>>> > It successfully deflates and inflates itself
>>> >
>>> > x?♣A☺☺   ? mcÿ7♣A♫☻?☺♂
>>> > ABCD
>>> >
>>> >
>>> > Hope this helps...
>>> >
>>> > [1] - 
>>> > https://gist.github.com/joebo/a3c2932f0e5a7a0c3f07#file-deflate-c-L2613
>>> > [2] - https://rawgit.com/nodeca/pako/master/dist/pako.js
>>> >
>>> > On Thu, Sep 11, 2014 at 11:33 AM, bill lam  wrote:
>>> >> This is strange since every author must had decode its own encoded
>>> >> data as a smoke test.
>>> >>
>>> >> Did you test if huffman code or bit lengths it produced was
>>> >> correct or not, ie it is a prefix coding and it satisfy the 2
>>> >> rules in rfc.
>>> >>
>>> >> Чт, 11 сен 2014, Joe Bogner написал(а):
>>> >>> unfortunately the dynamic coding in the putty fork doesn't seem to work:
>>> >>>
>>> >>> deflate -c deflate.c > out
>>> >>> deflate -d out
>>> >>>
>>> >>> decoding error: incorrect data checksum
>>> >>>
>>> >>>
>>> >>> it works fine with static tables
>>> >>>
>>> >>> C:\temp>echo ABCD > ABCD
>>> >>>
>>> >>> C:\temp>deflate -c ABCD > out
>>> >>>
>>> >>> C:\temp>deflate -d out
>>> >>> ABCD
>>> >>>
>>> >>> I added some debugging code to determine that deflating deflate.c
>>> >>> would be a dynamic table...  Assuming it's broke, I probably wouldn't
>>> >>> use it as a reference implementation after all
>>> >>>
>>> >>> On Thu, Sep 11, 2014 at 3:45 AM, bill lam  wrote:
>>> >>> > the frequencies (guessing from bit lengths) should be something like 
>>> >>> > 2 3 1 1
>>> >>> >   (2 3 1 1) hcodes 'ABCD'
>>> >>> >
>>> >>> > the hard part is the inverse problem: how to get the huffman code with
>>> >>> > prior knowing the bits for each symbol.  Your pointer to the putty
>>> >>> > fork looks like helpful.  The comment is in lines 861 to 914, the code
>>> >>> > itself in line 915 to 964. Do you know how to express it in J?
>>> >>> > Thanks.
>>> >>> >
>>> >>> > On Thu, Sep 11, 2014 at 2:57 PM, Joe Bogner  
>>> >>> > wrote:
>>> >>> >> Here a few other links ... after read

Re: [Jprogramming] Replace one item of a list

2014-09-11 Thread Raul Miller
Certainly.

"u/y applies the dyad u between the items of y".

This means that u is applied (#y)-1 times.

And an error would be inconsistent with the concept expressed for the
case where 0=#y.

Thanks,

-- 
Raul

On Thu, Sep 11, 2014 at 1:50 PM, Dan Bron  wrote:
> Pepe wrote:
>> My only question is: Does the Dictionary support this behavior?
>
> Raul responded:
>> Yes, it does.
>
> I am intrigued.  Can you elaborate?
>
> In particular, can you help me see, given only the text of the Dictionary,
> that  u/y  where 1=#y  must be  y  ?  And not, for example, an error?
>
> -Dan
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Replace one item of a list

2014-09-11 Thread Raul Miller
y always remains unchanged. Note also that the result is distinct from y:

   (-: +/) i.1
0

Thanks,

-- 
Raul

On Thu, Sep 11, 2014 at 3:13 PM, Jose Mario Quintana
 wrote:
> My only guess is:
> "m/y inserts successive verbs from the gerund m between items of y"
>
> So, if there is no "between items of y" inserts nothing and y remains
> unchanged; but, it seems to me that the Dictionary could be more assertive
> in this instance.
>
>
> On Thu, Sep 11, 2014 at 2:13 PM, Dan Bron  wrote:
>
>> Pepe wrote:
>> >  My only question is: Does the Dictionary support this behavior?
>>
>> > Raul responded:
>> >  Yes, it does.
>>
>> I replied:
>> >  I am intrigued.  Can you elaborate?
>>
>> Thomas followed-up:
>> >  I assumed that by not mentioning it, the implementation
>> >  is free to do what it chooses. It could be anything!
>>
>> That's what I think too.  The behavior is, in the strictest literal sense,
>> undefined.  But Raul differs. I'm interested in his rationale (which,
>> historically, has been both solid and instructive).
>>
>> -Dan
>>
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Replace one item of a list

2014-09-11 Thread Raul Miller
Remember that the definition of u/ was:

"u/y applies the dyad u between the items of y".

The items of i.1 are {.i.1

And:
   ({.i.1) -: +/i.1
1

Does that make sense? (And, yes, I intentionally mangled english
grammar in my third sentence of this message.)

Thanks,

-- 
Raul


On Thu, Sep 11, 2014 at 7:18 PM, Jose Mario Quintana
 wrote:
> Now, that is interesting.  Thus, it seems, the unofficial documentation
> about / is not quite correct (depending on what the meaning of "is" is.).
>
> I have another question: if "u is applied (#y)-1 times."  How come,
>
>(-: u^:0)i.1
> 1
>
> ?
>
>
>
> On Thu, Sep 11, 2014 at 6:36 PM, Raul Miller  wrote:
>
>> y always remains unchanged. Note also that the result is distinct from y:
>>
>>(-: +/) i.1
>> 0
>>
>> Thanks,
>>
>> --
>> Raul
>>
>> On Thu, Sep 11, 2014 at 3:13 PM, Jose Mario Quintana
>>  wrote:
>> > My only guess is:
>> > "m/y inserts successive verbs from the gerund m between items of y"
>> >
>> > So, if there is no "between items of y" inserts nothing and y remains
>> > unchanged; but, it seems to me that the Dictionary could be more
>> assertive
>> > in this instance.
>> >
>> >
>> > On Thu, Sep 11, 2014 at 2:13 PM, Dan Bron  wrote:
>> >
>> >> Pepe wrote:
>> >> >  My only question is: Does the Dictionary support this behavior?
>> >>
>> >> > Raul responded:
>> >> >  Yes, it does.
>> >>
>> >> I replied:
>> >> >  I am intrigued.  Can you elaborate?
>> >>
>> >> Thomas followed-up:
>> >> >  I assumed that by not mentioning it, the implementation
>> >> >  is free to do what it chooses. It could be anything!
>> >>
>> >> That's what I think too.  The behavior is, in the strictest literal
>> sense,
>> >> undefined.  But Raul differs. I'm interested in his rationale (which,
>> >> historically, has been both solid and instructive).
>> >>
>> >> -Dan
>> >>
>> >> --
>> >> For information about J forums see http://www.jsoftware.com/forums.htm
>> >>
>> > --
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] zlib huffman coding

2014-09-11 Thread Raul Miller
That's what I thought at first, also.

But, let's look at the example at
http://www.jsoftware.com/pipermail/programming/2014-September/039299.html

and the bit widths given at
http://www.jsoftware.com/pipermail/programming/2014-September/039327.html

Here's how it looks to me:

   bits -:#@>F hcodes A
0

Now.. is this a problem?

I think it is. Consider:

   #0 -.~#@>F hcodes A
286
   #0 -.~bits
260

Incidentally, I found a bug in my code, while trying to understand and
express this concept.

Fixed version here:

bl_count=:3 :0 NB. y is result of freqs
  0,}.<:#/.~(,~ [: i. 1 + >./)y
)

start_vals=: +:@+/\.&.|.@}:@,~&0

find_codes=:3 :0 NB. y is result of freqs
 b=. bl_count y
 v=. start_vals b
 n=. /:~ ~.y-.0
 o=. ;({./.~ /:~ (n (([#2:) #: ])&.> (*b)#v+&.>i.&.>b
 c /: o
)

An alternate version of the result from find_codes would be given by:

def_code=:3 :0
 b=. bl_count y
 v=. start_vals b
 n=. /:~ ~.y-.0
 o=. ;({./.~ /:~ ((*b)#v+&.>i.&.>b
 (,. i.@#)c /: o
)

Thanks,

-- 
Raul


On Thu, Sep 11, 2014 at 8:33 PM, Joe Bogner  wrote:
> The bit widths are calculated from the huffman tree
>
> See
>
> http://stackoverflow.com/questions/759707/efficient-way-of-storing-huffman-tree
>
> http://www.siggraph.org/education/materials/HyperGraph/video/mpeg/mpegfaq/huffman_tutorial.html
>
> The timing is interesting considering we were talking about trees the other
> day:
> http://jsoftware.2058.n7.nabble.com/Ragged-Array-Shapes-are-Trees-td63207.html
>
> I was thinking to myself then how I hadn't used trees more than a few times
> in 18 years of programming.
>
> I am not sure how to apply your code to the problem.  I also am not
> completely sure what problem we are solving.  If it is creating a
> standalone J deflate implementation or PNG compression it may be a tall
> order. I would be curious why not just interface to a C library like what
> is done in the image3 addon:
> http://www.jsoftware.com/jwiki/Addons/media/image3
> On Sep 11, 2014 6:27 PM, "Raul Miller"  wrote:
>
>> Here's the code I came up with, with Bill's help:
>>
>> bl_count=:3 :0 NB. y is result of freqs
>>   0,}.<:#/.~(,~ [: i. 1 + >./)y
>> )
>>
>> start_vals=: +:@+/\.&.|.@}:@,~&0
>>
>> find_codes=:3 :0 NB. y is result of freqs
>>  b=. bl_count y
>>  v=. start_vals b
>>  n=. /:~ ~.y-.0
>>  o=. ;({./.~ /:~ (>  c=. ;<"1&.>n (([#2:) #: ])&.> (*b)#v+&.>i.&.>b
>>  c /: o
>> )
>>
>> An alternate version of the result from find_codes would be given by:
>>
>> def_code=:3 :0
>>  b=. bl_count y
>>  v=. start_vals b
>>  n=. /:~ ~.y-.0
>>  o=. ;({./.~ /:~ (>  c=. ;n,.&.>(*b)#v+&.>i.&.>b
>>  (,. i.@#)c /: o
>> )
>>
>> The argument to find_codes or def_code is the bit widths for each symbol.
>>
>> I have not been able to figure out, from rfc 1951, how the bit widths
>> are calculated.
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>>
>> On Thu, Sep 11, 2014 at 4:47 PM, Joe Bogner  wrote:
>> > bill, I'd be interested in a solution but I don't think I can
>> > contribute any more on this. I played with
>> > https://code.google.com/p/miniz/ and became even more convinced of the
>> > complexity. It seems as though the compressor can decide whether to
>> > include the dictionary code table or not -- likely based on the size
>> > of the table.
>> >
>> >
>> > http://tools.ietf.org/html/rfc1950
>> >
>> > A preset dictionary is specially useful to compress short input
>> >   sequences. The compressor can take advantage of the dictionary
>> >   context to encode the input in a more compact manner.
>> >
>> >
>> > More links for anyone who is following and cares to go down the rabbit
>> hole too:
>> >
>> > http://en.wikipedia.org/wiki/Canonical_Huffman_code
>> >
>> >
>> http://stackoverflow.com/questions/759707/efficient-way-of-storing-huffman-tree
>> >
>> >
>> >
>> > On Thu, Sep 11, 2014 at 1:28 PM, bill lam  wrote:
>> >> This codes seemed invalid.
>> >>
>> >> 1 is a prefix of 11 which is a prefix of 111. Suppose there
>> >> is a bit pattern of 1 1 , it is ambiguous to mean
>> >> [68,'1']  [68,'1']
>> >> or [65,'11']
>> >>
>> >> The huffman code in rfc is canonical meaning there is exactly one
>> >> possible huffman codes fo

Re: [Jprogramming] zlib huffman coding

2014-09-11 Thread Raul Miller
If we define

bitlen=:4 :0
  b=. 0~:x
  b #inv #@>(b#x) hcodes b#y
)

Does it matter that these numbers are sometimes different from those
used in another implementation?

Thanks,

-- 
Raul


On Fri, Sep 12, 2014 at 12:59 AM, bill lam  wrote:
> Consider an example
>
>1 0 0 2 1 hcodes_jzlib_  i.5
> +-+---+---+-+---+
> |1 1 1|1 1 0 0|1 1 0 1|0|1 0|
> +-+---+---+-+---+
>#&> 1 0 0 2 1 hcodes_jzlib_  i.5
> 3 4 4 1 2
>(0~:1 0 0 2 1)* #&> 1 0 0 2 1 hcodes_jzlib_  i.5
> 3 0 0 1 2
>
> classic huffman did not expect a 0 frequency and if there were
> it assigns the longest bit length to them. I think this is
> reasonable because it must have a non-zero bit length to encode
> an entity.  For zlib, it seems that there is a third rule:
> For the bit length vector, bit lengths for zero frequency symbols
> are zero.
>
> From discussion here, I think using hcodes directly
> or indirectly for zlib is a wrong direction.
>
> Пт, 12 сен 2014, Raul Miller написал(а):
>> That's what I thought at first, also.
>>
>> But, let's look at the example at
>> http://www.jsoftware.com/pipermail/programming/2014-September/039299.html
>>
>> and the bit widths given at
>> http://www.jsoftware.com/pipermail/programming/2014-September/039327.html
>>
>> Here's how it looks to me:
>>
>>bits -:#@>F hcodes A
>> 0
>>
>> Now.. is this a problem?
>>
>> I think it is. Consider:
>>
>>#0 -.~#@>F hcodes A
>> 286
>>#0 -.~bits
>> 260
>>
>> Incidentally, I found a bug in my code, while trying to understand and
>> express this concept.
>>
>> Fixed version here:
>>
>> bl_count=:3 :0 NB. y is result of freqs
>>   0,}.<:#/.~(,~ [: i. 1 + >./)y
>> )
>>
>> start_vals=: +:@+/\.&.|.@}:@,~&0
>>
>> find_codes=:3 :0 NB. y is result of freqs
>>  b=. bl_count y
>>  v=. start_vals b
>>  n=. /:~ ~.y-.0
>>  o=. ;({./.~ /:~ (>  c=. ;<"1&.>n (([#2:) #: ])&.> (*b)#v+&.>i.&.>b
>>  c /: o
>> )
>>
>> An alternate version of the result from find_codes would be given by:
>>
>> def_code=:3 :0
>>  b=. bl_count y
>>  v=. start_vals b
>>  n=. /:~ ~.y-.0
>>  o=. ;({./.~ /:~ (>  c=. ;n,.&.>(*b)#v+&.>i.&.>b
>>  (,. i.@#)c /: o
>> )
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Thu, Sep 11, 2014 at 8:33 PM, Joe Bogner  wrote:
>> > The bit widths are calculated from the huffman tree
>> >
>> > See
>> >
>> > http://stackoverflow.com/questions/759707/efficient-way-of-storing-huffman-tree
>> >
>> > http://www.siggraph.org/education/materials/HyperGraph/video/mpeg/mpegfaq/huffman_tutorial.html
>> >
>> > The timing is interesting considering we were talking about trees the other
>> > day:
>> > http://jsoftware.2058.n7.nabble.com/Ragged-Array-Shapes-are-Trees-td63207.html
>> >
>> > I was thinking to myself then how I hadn't used trees more than a few times
>> > in 18 years of programming.
>> >
>> > I am not sure how to apply your code to the problem.  I also am not
>> > completely sure what problem we are solving.  If it is creating a
>> > standalone J deflate implementation or PNG compression it may be a tall
>> > order. I would be curious why not just interface to a C library like what
>> > is done in the image3 addon:
>> > http://www.jsoftware.com/jwiki/Addons/media/image3
>> > On Sep 11, 2014 6:27 PM, "Raul Miller"  wrote:
>> >
>> >> Here's the code I came up with, with Bill's help:
>> >>
>> >> bl_count=:3 :0 NB. y is result of freqs
>> >>   0,}.<:#/.~(,~ [: i. 1 + >./)y
>> >> )
>> >>
>> >> start_vals=: +:@+/\.&.|.@}:@,~&0
>> >>
>> >> find_codes=:3 :0 NB. y is result of freqs
>> >>  b=. bl_count y
>> >>  v=. start_vals b
>> >>  n=. /:~ ~.y-.0
>> >>  o=. ;({./.~ /:~ (> >>  c=. ;<"1&.>n (([#2:) #: ])&.> (*b)#v+&.>i.&.>b
>> >>  c /: o
>> >> )
>> >>
>> >> An alternate version of the result from find_codes would be given by:
>> >>
>> >> def_code=:3 :0
>> >>  b=. bl_count y
>> >>  v=. start_vals b
>> >>  n=. /:~ ~.y-.0
>> >>  o=. ;({./

Re: [Jprogramming] zlib huffman coding

2014-09-11 Thread Raul Miller
I thought the bit lengths were encoded in the file, not recreated by
an algorithm in the decoder?

Thanks,

-- 
Raul

On Fri, Sep 12, 2014 at 1:27 AM, bill lam  wrote:
> I think this matters a lot because output of our encoder will
> also be decoded by other zlib compliant decoders such as zlib.so
> itself. Or I had mis-read your question?
>
> Пт, 12 сен 2014, Raul Miller написал(а):
>> If we define
>>
>> bitlen=:4 :0
>>   b=. 0~:x
>>   b #inv #@>(b#x) hcodes b#y
>> )
>>
>> Does it matter that these numbers are sometimes different from those
>> used in another implementation?
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Fri, Sep 12, 2014 at 12:59 AM, bill lam  wrote:
>> > Consider an example
>> >
>> >1 0 0 2 1 hcodes_jzlib_  i.5
>> > +-+---+---+-+---+
>> > |1 1 1|1 1 0 0|1 1 0 1|0|1 0|
>> > +-+---+---+-+---+
>> >#&> 1 0 0 2 1 hcodes_jzlib_  i.5
>> > 3 4 4 1 2
>> >(0~:1 0 0 2 1)* #&> 1 0 0 2 1 hcodes_jzlib_  i.5
>> > 3 0 0 1 2
>> >
>> > classic huffman did not expect a 0 frequency and if there were
>> > it assigns the longest bit length to them. I think this is
>> > reasonable because it must have a non-zero bit length to encode
>> > an entity.  For zlib, it seems that there is a third rule:
>> > For the bit length vector, bit lengths for zero frequency symbols
>> > are zero.
>> >
>> > From discussion here, I think using hcodes directly
>> > or indirectly for zlib is a wrong direction.
>> >
>> > Пт, 12 сен 2014, Raul Miller написал(а):
>> >> That's what I thought at first, also.
>> >>
>> >> But, let's look at the example at
>> >> http://www.jsoftware.com/pipermail/programming/2014-September/039299.html
>> >>
>> >> and the bit widths given at
>> >> http://www.jsoftware.com/pipermail/programming/2014-September/039327.html
>> >>
>> >> Here's how it looks to me:
>> >>
>> >>bits -:#@>F hcodes A
>> >> 0
>> >>
>> >> Now.. is this a problem?
>> >>
>> >> I think it is. Consider:
>> >>
>> >>#0 -.~#@>F hcodes A
>> >> 286
>> >>#0 -.~bits
>> >> 260
>> >>
>> >> Incidentally, I found a bug in my code, while trying to understand and
>> >> express this concept.
>> >>
>> >> Fixed version here:
>> >>
>> >> bl_count=:3 :0 NB. y is result of freqs
>> >>   0,}.<:#/.~(,~ [: i. 1 + >./)y
>> >> )
>> >>
>> >> start_vals=: +:@+/\.&.|.@}:@,~&0
>> >>
>> >> find_codes=:3 :0 NB. y is result of freqs
>> >>  b=. bl_count y
>> >>  v=. start_vals b
>> >>  n=. /:~ ~.y-.0
>> >>  o=. ;({./.~ /:~ (> >>  c=. ;<"1&.>n (([#2:) #: ])&.> (*b)#v+&.>i.&.>b
>> >>  c /: o
>> >> )
>> >>
>> >> An alternate version of the result from find_codes would be given by:
>> >>
>> >> def_code=:3 :0
>> >>  b=. bl_count y
>> >>  v=. start_vals b
>> >>  n=. /:~ ~.y-.0
>> >>  o=. ;({./.~ /:~ (> >>  c=. ;n,.&.>(*b)#v+&.>i.&.>b
>> >>  (,. i.@#)c /: o
>> >> )
>> >>
>> >> Thanks,
>> >>
>> >> --
>> >> Raul
>> >>
>> >>
>> >> On Thu, Sep 11, 2014 at 8:33 PM, Joe Bogner  wrote:
>> >> > The bit widths are calculated from the huffman tree
>> >> >
>> >> > See
>> >> >
>> >> > http://stackoverflow.com/questions/759707/efficient-way-of-storing-huffman-tree
>> >> >
>> >> > http://www.siggraph.org/education/materials/HyperGraph/video/mpeg/mpegfaq/huffman_tutorial.html
>> >> >
>> >> > The timing is interesting considering we were talking about trees the 
>> >> > other
>> >> > day:
>> >> > http://jsoftware.2058.n7.nabble.com/Ragged-Array-Shapes-are-Trees-td63207.html
>> >> >
>> >> > I was thinking to myself then how I hadn't used trees more than a few 
>> >> > times
>> >> > in 18 years of programming.
>> >> >
>> >> > 

Re: [Jprogramming] rpn calculator

2014-09-12 Thread Raul Miller
Here's a few examples that relate to how I think of A. ...

   (i.6) A. i.3
0 1 2
0 2 1
1 0 2
1 2 0
2 0 1
2 1 0

The number of permutations is the factorial of the number of items
being permuted.

   (0,~.!i.6) A. i.6
0 1 2 3 4 5
0 1 2 3 5 4
0 1 2 4 3 5
0 1 3 2 4 5
0 2 1 3 4 5
1 0 2 3 4 5

Permutation numbers which are factorials move a value one place to the
right and the value that was at that location gets moved one place to
the right. (It's a simple swap.) The larger the factorial, the farther
from the right it is where this swap occurs.

   0,(,*/)!3 5
0 6 120 720
   (0,(,+/)!3 5) A. i.8
0 1 2 3 4 5 6 7
0 1 2 3 5 4 6 7
0 1 3 2 4 5 6 7
0 1 3 2 5 4 6 7

Independent permutations compose additively.

This could also be thought of as true of overlapping permutations, but
addition is commutative and permutations are not, so for you'd need to
impose some sort of canonical ordering constraint for that abstraction
to make sense when phrased that way.

   (!4) A. (!5) A. i. 8
0 1 3 4 2 5 6 7
   (!5) A. (!4) A. i. 8
0 1 4 2 3 5 6 7

And that's probably more than most anyone wanted to know about this topic.

-- 
Raul


On Fri, Sep 12, 2014 at 3:31 PM, Dan Bron  wrote:
> Brian Schott wrote:
>>  1 A. b transposes the last two items of b
>
> A. is really cool. The problem with using it is coming up with the correct
> left-hand argument (code) for the permutation you want. A few special ones
> are easy to remember (particularly 0 for "do nothing", _1 for "reverse",
> and 1 for "swap")*, but outside of these, the codes are quite obscure.
>
> The most straightforward method for identifying the anagram code you want
> is by creating the desired permutation vector manually, then applying the
> *monad* A. to it, and using the resulting output as a LHA to the dyad A.
> against your real argument later.
>
> The real high road would be to study and understand the model of A. Roger
> provided [1], but that's been on my to-do list for just about a decade.
> Don't have much hope it'll get done in the next one, either (though I find
> the /:^:2@:,/ for "direct cycle representation from anagram code" part
> intriguing!).
>
> -Dan
>
> * One example that sticks in my mind of where these special anagram codes
> came in quite handy was the "zig zag matrix" puzzle. I once wrote up an
> explanation of it (including the A. parts) on RosettaCode:
>
>  http://rosettacode.org/wiki/Talk:Zig-zag_matrix#anti-diagonals
>
> [1] Roger's model of A., including the interpretation and calculation of
> "anagram codes" (i.e. the results of monad A., and the LHA to dyad A.):
> http://www.jsoftware.com/pipermail/general/1999-September/002352.html
>
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] wait, what?

2014-09-12 Thread Raul Miller
Apparently this is legal:

   (152{a.)=: i.3 3

I was surprised.

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


Re: [Jprogramming] Using a data arrays to send images

2014-09-12 Thread Raul Miller
Here's what I notice:

In your first example, the largest possible value in Q was 9, and you
referred to GRB256 even though you had not yet defined it.

In your second example, the largest possible value in Q was greater than 999.

Inspecting samples of the data (try 3 3 {.Q and 3 3 {. S) should make
the significance of the "largest possible value" issue apparent.

Thanks,

-- 
Raul


On Fri, Sep 12, 2014 at 4:09 PM, Linda Alvord  wrote:
> This is the real problem I'm working on.  Here's what works.
>
>
>
> load 'viewmat'
>
> GRB=:1 0 2{"1 ( #:i.8){0 255
>
> p=: 13 :'?.(y,y)$y'
>
> ]Q=:p 10
>
> ]R=:10 #. Q
>
> ]S=:(10$10)#:R
>
> Q-:S
>
>
>
> GRB256 viewmat Q;'Q'
>
> GRB256 viewmat S;'S'
>
>
>
> Q is a random array of data which has a corresponding color image.The data
> is coded in base 10. That list is then transformed into an array S .  Q
> matches S and image S is like image Q.
>
>
>
> Here's where it doesn't work.
>
>
>
> load 'viewmat'
>
> GRB256=:1 0 2({"1) 256 256 256#:i.256^3
>
> Q=:?(1000 1000)$ 16777216x
>
>
>
> R=:1000 #. Q
>
> S=:(1000$1000) #: R
>
> Q-:S
>
>
>
> GRB256 viewmat Q;'Q'
>
> GRB256 viewmat S;'S'
>
>
>
> Q and R seem to be what I expected, but something is wrong with S.  Any
> ideas?
>
>
>
> Linda
>
>
>
>
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] wait, what?

2014-09-12 Thread Raul Miller
I was using jqt 802 on desktop.

FYI,

-- 
Raul


On Fri, Sep 12, 2014 at 9:09 PM, bill lam  wrote:
> J implementation only allows 7 bit ascii alphabets for name. This is
> relaxed in the unofficial android jqt.
>
>(a=.152{a.)=. i.3 3
>a~
> 0 1 2
> 3 4 5
> 6 7 8
>水=.i. 2 2
>水
> 0 1
> 2 3
>йцфы=.i.3 3
>йцфы
> 0 1 2
> 3 4 5
> 6 7 8
>
>  On Sep 13, 2014 8:38 AM, "Raul Miller"  wrote:
>
>> Apparently this is legal:
>>
>>(152{a.)=: i.3 3
>>
>> I was surprised.
>>
>> --
>> Raul
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] wait, what?

2014-09-12 Thread Raul Miller
I get an ill-formed name error.

Thanks,

-- 
Raul

On Fri, Sep 12, 2014 at 10:25 PM, bill lam  wrote:
> May be you can try this,
>u:955
> λ
>(a=.utf8 u:955)=. i.2 3
>a
> λ
>a~
> 0 1 2
> 3 4 5
>λ
> 0 1 2
> 3 4 5
>λ * 2
> 0 2  4
> 6 8 10
>
> I cannot type lambda, the lambda was copied from the output in j session.
> Tested on android only.
> On Sep 13, 2014 10:11 AM, "Don Guinn"  wrote:
>
>> Well it defined it in Windows 7 version of J, but couldn't access it.
>> (152{a.)=: i.3 3
>>(152{a.)
>> �
>>names 0
>> aspect  filler  filter_size g   gussian kernel_size
>> m   n   r2  rho zks �
>>�
>> |spelling error
>> |   �
>> |   ^
>>
>> It showed up as a box in the J window. No telling what your browser sees.
>>
>> On Fri, Sep 12, 2014 at 7:09 PM, bill lam  wrote:
>>
>> > J implementation only allows 7 bit ascii alphabets for name. This is
>> > relaxed in the unofficial android jqt.
>> >
>> >(a=.152{a.)=. i.3 3
>> >a~
>> > 0 1 2
>> > 3 4 5
>> > 6 7 8
>> >水=.i. 2 2
>> >水
>> > 0 1
>> > 2 3
>> >йцфы=.i.3 3
>> >йцфы
>> > 0 1 2
>> > 3 4 5
>> > 6 7 8
>> >
>> >  On Sep 13, 2014 8:38 AM, "Raul Miller"  wrote:
>> >
>> > > Apparently this is legal:
>> > >
>> > >(152{a.)=: i.3 3
>> > >
>> > > I was surprised.
>> > >
>> > > --
>> > > Raul
>> > > --
>> > > For information about J forums see http://www.jsoftware.com/forums.htm
>> > >
>> > --
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> >
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] wait, what?

2014-09-12 Thread Raul Miller
Looking for other examples:

   (128}.i.65536)#~_2 wrote:
> May be you can try this,
>u:955
> λ
>(a=.utf8 u:955)=. i.2 3
>a
> λ
>a~
> 0 1 2
> 3 4 5
>λ
> 0 1 2
> 3 4 5
>λ * 2
> 0 2  4
> 6 8 10
>
> I cannot type lambda, the lambda was copied from the output in j session.
> Tested on android only.
> On Sep 13, 2014 10:11 AM, "Don Guinn"  wrote:
>
>> Well it defined it in Windows 7 version of J, but couldn't access it.
>> (152{a.)=: i.3 3
>>(152{a.)
>> �
>>names 0
>> aspect  filler  filter_size g   gussian kernel_size
>> m   n   r2  rho zks �
>>�
>> |spelling error
>> |   �
>> |   ^
>>
>> It showed up as a box in the J window. No telling what your browser sees.
>>
>> On Fri, Sep 12, 2014 at 7:09 PM, bill lam  wrote:
>>
>> > J implementation only allows 7 bit ascii alphabets for name. This is
>> > relaxed in the unofficial android jqt.
>> >
>> >(a=.152{a.)=. i.3 3
>> >a~
>> > 0 1 2
>> > 3 4 5
>> > 6 7 8
>> >水=.i. 2 2
>> >水
>> > 0 1
>> > 2 3
>> >йцфы=.i.3 3
>> >йцфы
>> > 0 1 2
>> > 3 4 5
>> > 6 7 8
>> >
>> >  On Sep 13, 2014 8:38 AM, "Raul Miller"  wrote:
>> >
>> > > Apparently this is legal:
>> > >
>> > >(152{a.)=: i.3 3
>> > >
>> > > I was surprised.
>> > >
>> > > --
>> > > Raul
>> > > --
>> > > For information about J forums see http://www.jsoftware.com/forums.htm
>> > >
>> > --
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> >
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] zlib huffman coding

2014-09-13 Thread Raul Miller
If we use hcodes to get bit lengths, and another mechanism (I think the
last one I posted is adequate) to determine the bit values, there should be
no reason to iterate further. The two extra constraints should never
require that bit lengths be changed.

Thanks,

-- 
Raul

On Sat, Sep 13, 2014 at 12:43 PM, bill lam  wrote:

> I try the putty fork, its seems fialed to uncompress it own
> compressed data.  Perhaps its compressed data is malformed.
>
> I also look at the trees.c of the the official zlib. I do not
> understand the code, too complex for me.  AFAICU it does not
> generate huffman codes using any standard algorithm, but it
> assigns bit lengths using some heuristics (trail and error).
> I guess we can try using hcodes to get an initial guess of bit
> lengths and then iterate to make it satisfy the 2 rules.
>
> Чт, 11 сен 2014, bill lam написал(а):
> > the frequencies (guessing from bit lengths) should be something like 2 3
> 1 1
> >   (2 3 1 1) hcodes 'ABCD'
> >
> > the hard part is the inverse problem: how to get the huffman code with
> > prior knowing the bits for each symbol.  Your pointer to the putty
> > fork looks like helpful.  The comment is in lines 861 to 914, the code
> > itself in line 915 to 964. Do you know how to express it in J?
> > Thanks.
> >
> > On Thu, Sep 11, 2014 at 2:57 PM, Joe Bogner  wrote:
> > > Here a few other links ... after reading through the RFC. Not sure if
> > > they help, but just sharing from my own research into assisting on
> > > this topic
> > >
> > > https://github.com/evegard/pngview/blob/master/huffman.c#L54
> > >
> > > And a fork of the putty version with dynamic huffman coding:
> > >
> http://rc.quest.com/viewvc/putty/trunk/halibut/deflate.c?diff_format=s&revision=2&view=markup
> > >
> > > Or just generally googling some of the code from the RFC:
> > >
> https://www.google.com/search?q=next_code%5Blen%5D%2B%2B%3B&oq=next_code%5Blen%5D%2B%2B%3B&aqs=chrome..69i57.387j0j7&sourceid=chrome&es_sm=93&ie=UTF-8#q=next_code%5Blen%5D%2B%2B%3B&start=20
> > >
> > >
> > > Using the code from
> > > http://www.jsoftware.com/jwiki/Essays/Huffman%20Coding, I got stuck
> > > trying to match a simple example to the binary tree in the RFC:
> > >
> > > From the RFC:
> > >
> > >   /\  SymbolCode
> > >  0  1 --
> > > /\A  00
> > >/\ B   B   1
> > >   0  1C 011
> > >  /\   D 010
> > > A /\
> > >  0  1
> > > /\
> > >D  C
> > >
> > >
> > >
> > >(4#1) hcodes 'ABCD'
> > > ┌───┬───┬───┬───┐
> > > │0 0│0 1│1 0│1 1│
> > > └───┴───┴───┴───┘
> > >
> > > Per the RFC, ideally that should match this? '00';'1';'011';'010'
> > >
> > >
> > > From there, it seems like a pretty straightforward exercise to
> > > transliterate the C code from the RFC into J code to recode the
> > > example to:
> > >
> > >
> > > Symbol  Code
> > > --  
> > > A   10
> > > B   0
> > > C   110
> > > D   111
> > >
> > >
> > > I would probably start with a looping construct like what's in the RFC
> > > and then figure out a more J way to do it, but first I would need to
> > > figure out how to create the binary tree in that initial format.
> > >
> > > On Wed, Sep 10, 2014 at 7:41 PM, bill lam  wrote:
> > >> Thanks Joe,
> > >> putty only use zlib static huffman for encoding so that it does not
> build
> > >> any huffman dictionary table.
> > >>
> > >> The zlib static huffman code does not care about individual symbol's
> > >> frequency, it just encode 0 to 286 into bits, see section 3.2.6.
> > >>  On Sep 11, 2014 1:26 AM, "Joe Bogner"  wrote:
> > >>
> > >>> You've already likely considered this, but if it were me I would
> compare
> > >>> results to a working implementation. The one from putty seems 

Re: [Jprogramming] zlib huffman coding

2014-09-13 Thread Raul Miller
Here's a perhaps slightly more efficient way of computing bit lengths:

bitlens=: 4 :0
  t=. 0{:: x hc w=. ,&.> y
  (( wrote:

> Raul, I just tried your code and confirmed that it returned the same
> results as mine:
>
> find_codes (3, 3, 3, 3,3, 2, 4, 4)
> ┌─┬─┬─┬─┬─┬───┬───┬───┐
> │0 1 0│0 1 1│1 0 0│1 0 1│1 1 0│0 0│1 1 1 0│1 1 1 1│
> └─┴─┴─┴─┴─┴───┴───┴───┘
>
> #: inv every find_codes (3, 3, 3, 3,3, 2, 4, 4)
> 2 3 4 5 6 0 14 15
>
> tree=: makeFromLengths (3, 3, 3, 3,3, 2, 4, 4)
> tree
>
> 2 3 4 5 6 0 14 15
>
> #: tree
> 0 0 1 0
> 0 0 1 1
> 0 1 0 0
> 0 1 0 1
> 0 1 1 0
> 0 0 0 0
> 1 1 1 0
> 1 1 1 1
>
> I like the looks of yours more. Mine was a transliteration from the
> RFC. I will need to study yours as I don't understand it yet.
>
> I agree that using hcodes with either mine or yours should produce
> what's needed per the RFC, at least the steps we were looking at in
> the RFC. There is likely more solve still beyond that
>
>
> On Sat, Sep 13, 2014 at 2:52 PM, Raul Miller 
> wrote:
> > If we use hcodes to get bit lengths, and another mechanism (I think the
> > last one I posted is adequate) to determine the bit values, there should
> be
> > no reason to iterate further. The two extra constraints should never
> > require that bit lengths be changed.
> >
> > Thanks,
> >
> > --
> > Raul
> >
> > On Sat, Sep 13, 2014 at 12:43 PM, bill lam  wrote:
> >
> >> I try the putty fork, its seems fialed to uncompress it own
> >> compressed data.  Perhaps its compressed data is malformed.
> >>
> >> I also look at the trees.c of the the official zlib. I do not
> >> understand the code, too complex for me.  AFAICU it does not
> >> generate huffman codes using any standard algorithm, but it
> >> assigns bit lengths using some heuristics (trail and error).
> >> I guess we can try using hcodes to get an initial guess of bit
> >> lengths and then iterate to make it satisfy the 2 rules.
> >>
> >> Чт, 11 сен 2014, bill lam написал(а):
> >> > the frequencies (guessing from bit lengths) should be something like
> 2 3
> >> 1 1
> >> >   (2 3 1 1) hcodes 'ABCD'
> >> >
> >> > the hard part is the inverse problem: how to get the huffman code with
> >> > prior knowing the bits for each symbol.  Your pointer to the putty
> >> > fork looks like helpful.  The comment is in lines 861 to 914, the code
> >> > itself in line 915 to 964. Do you know how to express it in J?
> >> > Thanks.
> >> >
> >> > On Thu, Sep 11, 2014 at 2:57 PM, Joe Bogner 
> wrote:
> >> > > Here a few other links ... after reading through the RFC. Not sure
> if
> >> > > they help, but just sharing from my own research into assisting on
> >> > > this topic
> >> > >
> >> > > https://github.com/evegard/pngview/blob/master/huffman.c#L54
> >> > >
> >> > > And a fork of the putty version with dynamic huffman coding:
> >> > >
> >>
> http://rc.quest.com/viewvc/putty/trunk/halibut/deflate.c?diff_format=s&revision=2&view=markup
> >> > >
> >> > > Or just generally googling some of the code from the RFC:
> >> > >
> >>
> https://www.google.com/search?q=next_code%5Blen%5D%2B%2B%3B&oq=next_code%5Blen%5D%2B%2B%3B&aqs=chrome..69i57.387j0j7&sourceid=chrome&es_sm=93&ie=UTF-8#q=next_code%5Blen%5D%2B%2B%3B&start=20
> >> > >
> >> > >
> >> > > Using the code from
> >> > > http://www.jsoftware.com/jwiki/Essays/Huffman%20Coding, I got stuck
> >> > > trying to match a simple example to the binary tree in the RFC:
> >> > >
> >> > > From the RFC:
> >> > >
> >> > >   /\  SymbolCode
> >> > >  0  1 --
> >> > > /\A  00
> >> > >/\ B   B   1
> >> > >   0  1C 011
> >> > >  /\   D 010
> >> > > A /\
> >> > >  0  1
> >> > > /\
> >> > >D  C
> >> > >

Re: [Jprogramming] zlib huffman coding

2014-09-14 Thread Raul Miller
Oops, yes, I should incorporate the zero test into bitlens.


bitlens=: 4 :0
  t=. 0{:: x hc w=. ,&.> y
  (*x)*(( wrote:

> Thanks Raul and Joe,
>
> The problem seemed now solved. It turns out that how to get bit length
> was a red herring. The main problem is huffman coding is in-applicable
> to zero bit of information, ie the universe has only 0 or 1
> symbol. eg, the result of bitlen 0 0 0  or bitlen 1 0 0 0 0 cannot
> be correct (GIGO).  However such input actually happens in zlib
> compression and section 4 of rfc,
>
>   ...  If only one distance
>   code is used, it is encoded using one bit, not zero bits; in
>   this case there is a single code length of one, with one unused
>   code.  One distance code of zero bits means that there are no
>   distance codes used at all ...
>
> Now arc/zlib addon enables dynamic huffman coding. Thank you
> both of you for patience and help.
>
> BTW I found the new bitlens has some problems, first it should
> zero out bit length of zero frequency on output.
>
> 1 0 1 bitlen i.3
> 1 0 1
>
> 1 0 1 bitlens i.3
> 2 2 1
>
> Actually 1 bit can encode 2 symbols, data encoded by it were
> rejected during decoding with zlib.so even after masked off
> the zero frequency entries.
>
> What did you mean by "data is well formed"?
>
>
> Вс, 14 сен 2014, Raul Miller написал(а):
> > Here's a perhaps slightly more efficient way of computing bit lengths:
> >
> > bitlens=: 4 :0
> >   t=. 0{:: x hc w=. ,&.> y
> >   (( > )
> >
> > This assumes that the data is well formed, but the big thing is that it
> > does not compute a boxed intermediate result and instead finds the
> lengths
> > earlier in the process.
> >
> > Thanks,
> >
> > --
> > Raul
> >
> > On Sat, Sep 13, 2014 at 3:41 PM, Joe Bogner  wrote:
> >
> > > Raul, I just tried your code and confirmed that it returned the same
> > > results as mine:
> > >
> > > find_codes (3, 3, 3, 3,3, 2, 4, 4)
> > > ┌─┬─┬─┬─┬─┬───┬───┬───┐
> > > │0 1 0│0 1 1│1 0 0│1 0 1│1 1 0│0 0│1 1 1 0│1 1 1 1│
> > > └─┴─┴─┴─┴─┴───┴───┴───┘
> > >
> > > #: inv every find_codes (3, 3, 3, 3,3, 2, 4, 4)
> > > 2 3 4 5 6 0 14 15
> > >
> > > tree=: makeFromLengths (3, 3, 3, 3,3, 2, 4, 4)
> > > tree
> > >
> > > 2 3 4 5 6 0 14 15
> > >
> > > #: tree
> > > 0 0 1 0
> > > 0 0 1 1
> > > 0 1 0 0
> > > 0 1 0 1
> > > 0 1 1 0
> > > 0 0 0 0
> > > 1 1 1 0
> > > 1 1 1 1
> > >
> > > I like the looks of yours more. Mine was a transliteration from the
> > > RFC. I will need to study yours as I don't understand it yet.
> > >
> > > I agree that using hcodes with either mine or yours should produce
> > > what's needed per the RFC, at least the steps we were looking at in
> > > the RFC. There is likely more solve still beyond that
> > >
> > >
> > > On Sat, Sep 13, 2014 at 2:52 PM, Raul Miller 
> > > wrote:
> > > > If we use hcodes to get bit lengths, and another mechanism (I think
> the
> > > > last one I posted is adequate) to determine the bit values, there
> should
> > > be
> > > > no reason to iterate further. The two extra constraints should never
> > > > require that bit lengths be changed.
> > > >
> > > > Thanks,
> > > >
> > > > --
> > > > Raul
> > > >
> > > > On Sat, Sep 13, 2014 at 12:43 PM, bill lam 
> wrote:
> > > >
> > > >> I try the putty fork, its seems fialed to uncompress it own
> > > >> compressed data.  Perhaps its compressed data is malformed.
> > > >>
> > > >> I also look at the trees.c of the the official zlib. I do not
> > > >> understand the code, too complex for me.  AFAICU it does not
> > > >> generate huffman codes using any standard algorithm, but it
> > > >> assigns bit lengths using some heuristics (trail and error).
> > > >> I guess we can try using hcodes to get an initial guess of bit
> > > >> lengths and then iterate to make it satisfy the 2 rules.
> > > >>
> > > >> Чт, 11 сен 2014, bill lam написал(а):
> > > >> > the frequencies (guessing from bit lengths) should be something
> like
> > > 2 3
> > > >> 1 1
> > > >> >   (2 3 1 1) hcodes 'ABC

Re: [Jprogramming] zlib huffman coding

2014-09-14 Thread Raul Miller
Let's do it like this, maybe:

def_code=:3 :0
 f=. (*y)#y
 b=. bl_count f
 v=. start_vals b
 n=. /:~ ~.f
 o=. ;({./.~ /:~ ((*b)#v+&.>i.&.>b
 (I.*y),.~ c /: o
)

Note that I've not included the special case exception result for all
zeros. I believe that that breaks so many assumptions that I think it
should be handled at a higher level.

Thanks,

-- 
Raul


On Sun, Sep 14, 2014 at 8:29 AM, bill lam  wrote:

> In the last of def_code
> (,. i.@#)c /: o
> has a bug in that the index of non-zero I.0~:y instead of i@# should be
> stitched. Thanks.
> On Sep 12, 2014 12:25 PM, "Raul Miller"  wrote:
>
> That's what I thought at first, also.
>
> But, let's look at the example at
> http://www.jsoftware.com/pipermail/programming/2014-September/039299.html
>
> and the bit widths given at
> http://www.jsoftware.com/pipermail/programming/2014-September/039327.html
>
> Here's how it looks to me:
>
>bits -:#@>F hcodes A
> 0
>
> Now.. is this a problem?
>
> I think it is. Consider:
>
>#0 -.~#@>F hcodes A
> 286
>#0 -.~bits
> 260
>
> Incidentally, I found a bug in my code, while trying to understand and
> express this concept.
>
> Fixed version here:
>
> bl_count=:3 :0 NB. y is result of freqs
>   0,}.<:#/.~(,~ [: i. 1 + >./)y
> )
>
> start_vals=: +:@+/\.&.|.@}:@,~&0
>
> find_codes=:3 :0 NB. y is result of freqs
>  b=. bl_count y
>  v=. start_vals b
>  n=. /:~ ~.y-.0
>  o=. ;({./.~ /:~ (  c=. ;<"1&.>n (([#2:) #: ])&.> (*b)#v+&.>i.&.>b
>  c /: o
> )
>
> An alternate version of the result from find_codes would be given by:
>
> def_code=:3 :0
>  b=. bl_count y
>  v=. start_vals b
>  n=. /:~ ~.y-.0
>  o=. ;({./.~ /:~ (  c=. ;n,.&.>(*b)#v+&.>i.&.>b
>  (,. i.@#)c /: o
> )
>
> Thanks,
>
> --
> Raul
>
>
> On Thu, Sep 11, 2014 at 8:33 PM, Joe Bogner  wrote:
> > The bit widths are calculated from the huffman tree
> >
> > See
> >
> >
>
> http://stackoverflow.com/questions/759707/efficient-way-of-storing-huffman-tree
> >
> >
>
> http://www.siggraph.org/education/materials/HyperGraph/video/mpeg/mpegfaq/huffman_tutorial.html
> >
> > The timing is interesting considering we were talking about trees the
> other
> > day:
> >
>
> http://jsoftware.2058.n7.nabble.com/Ragged-Array-Shapes-are-Trees-td63207.html
> >
> > I was thinking to myself then how I hadn't used trees more than a few
> times
> > in 18 years of programming.
> >
> > I am not sure how to apply your code to the problem.  I also am not
> > completely sure what problem we are solving.  If it is creating a
> > standalone J deflate implementation or PNG compression it may be a tall
> > order. I would be curious why not just interface to a C library like what
> > is done in the image3 addon:
> > http://www.jsoftware.com/jwiki/Addons/media/image3
> > On Sep 11, 2014 6:27 PM, "Raul Miller"  wrote:
> >
> >> Here's the code I came up with, with Bill's help:
> >>
> >> bl_count=:3 :0 NB. y is result of freqs
> >>   0,}.<:#/.~(,~ [: i. 1 + >./)y
> >> )
> >>
> >> start_vals=: +:@+/\.&.|.@}:@,~&0
> >>
> >> find_codes=:3 :0 NB. y is result of freqs
> >>  b=. bl_count y
> >>  v=. start_vals b
> >>  n=. /:~ ~.y-.0
> >>  o=. ;({./.~ /:~ ( >>  c=. ;<"1&.>n (([#2:) #: ])&.> (*b)#v+&.>i.&.>b
> >>  c /: o
> >> )
> >>
> >> An alternate version of the result from find_codes would be given by:
> >>
> >> def_code=:3 :0
> >>  b=. bl_count y
> >>  v=. start_vals b
> >>  n=. /:~ ~.y-.0
> >>  o=. ;({./.~ /:~ ( >>  c=. ;n,.&.>(*b)#v+&.>i.&.>b
> >>  (,. i.@#)c /: o
> >> )
> >>
> >> The argument to find_codes or def_code is the bit widths for each
> symbol.
> >>
> >> I have not been able to figure out, from rfc 1951, how the bit widths
> >> are calculated.
> >>
> >> Thanks,
> >>
> >> --
> >> Raul
> >>
> >>
> >>
> >> On Thu, Sep 11, 2014 at 4:47 PM, Joe Bogner 
> wrote:
> >> > bill, I'd be interested in a solution but I don't think I can
> >> > contribute any more on this. I played with
> >> > https://code.google.com/p/miniz/ and became even more convinced of
> the
> >> > complexity. It seems as though the compre

Re: [Jprogramming] OOJ and calling a verb from another locale

2014-09-15 Thread Raul Miller
I can see two things you are doing wrong here, perhaps three.

First, consider:

   myVerb=: +/ % #
   MyVerb 1 2 3
|value error

J is case sensitive.

Next, consider:
   coname''
base
   myVerb_base_
+/ % #
   myVerb_z_
|value error

You defined myVerb in the base locale, and not in the z locale.

So that's two things.

Next let's consider the design of your constructor:

coclass 'MyClass'

create=: verb define
  myValue=: ".y
)

This says that you are expecting the constructor to be getting an sentence
which will be evaluated in the object's locale. That means that any names
would have to be defined in the z locale or in your class definition
definition (by default your object inherits from z and the class but not
from any other locale). So that's the possible third problem.

You might instead want the object to inherit from some other locale (in
this example, you have implied you are interested in the base locale). You
could make the class inherit from base:

coclass 'MyClass'
coinsert 'base'

create=: verb define
  myValue=: ".y
)

Or maybe you think that that is a bad idea, and instead only want the
sentence to be evaluated in the base locale:

coclass 'MyClass'

create=: verb define
  myValue=: do_base_ y
)

(There is no way to discover what locale you were called from unless
debugging was enabled before the call was made, or unless some
programmer-imposed convention was used to identify the calling locale.)

Of course, you could just specify the locale where the name was defined in
the sentence you pass to the constructor:

   'myVerb_base_ 1 2 3' conew 'MyClass'
+-+
|5|
+-+
   myValue_5_
2

I'd also take note of the other responses you've gotten.

Thanks,

-- 
Raul






On Mon, Sep 15, 2014 at 10:38 AM, Jon Hough  wrote:

> OOJ = object oriented J
> I have a preexisting verb, for example lets call it myVerb =. +/ % #.
> Next I define a class:
> coclass 'MyClass'
> create =: verb define   myValue =: ". y
> )
> So, essentialy my value is going to run the command y, using verb ".
> So perhaps I want y to by 'myVerb 1 2 3'
> Then, hopefully myValue will be 2.
> So I do
> myObj =: conew 'MyClass'
> create__myObj 'MyVerb 1 2 3'
> However, I get a value error for MyVerb. I asusme this is because myVerb
> was defined in a different locale.
> I then tried create__myObj 'MyVerb_z_ 1 2 3'
> Which also gives a value error.
> By the way, what I am trying to do is pass a callback to the constructor
> of MyClass, so I can execute an arbitrary function. I am using ". to call
> the arbitrary function. I think this method of callbacks was shown in J for
> C.
> So the question is, what is my code doing wrong?
> Thanks.
>
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] orthogonalizing a matrix

2014-09-16 Thread Raul Miller
Here's another power iterator approach:

   {."2 ({. f"1 }.)^:(i.@#) !/~i.10

And here's a looping explicit approach:

orto=:3 :0
  a=. 1 {. y
  for. i.(#y)-1 do.
a=.a,{.y=.({:a)f"1}.y
  end.
)

The explicit approach should be more efficient on very large arguments, but
has no advantage on a 10 by 10.

Thanks,

-- 
Raul

On Tue, Sep 16, 2014 at 4:46 AM, Aai  wrote:

> I'm not sure if this is less embarrassing, but here's an power iterator
> solution:
>
> 0{::([ ((,{.);]) {:@[ f"1 }.@])&>/^:(<:@#`(,:@{.;])) !/~i.10
>
>
>
> On 16-09-14 08:56, 'Bo Jacoby' via Programming wrote:
>
>> I managed to ortogonalize a 10 10 - matrix like this:
>>
>> f=.[:(%+./)(]*[:+/[*[)-[*[:+/*
>> orto =. 3 : 0
>> a=.,:{.y
>> a=.a,{.y=.({:a)f"1}.y
>> a=.a,{.y=.({:a)f"1}.y
>> a=.a,{.y=.({:a)f"1}.y
>> a=.a,{.y=.({:a)f"1}.y
>> a=.a,{.y=.({:a)f"1}.y
>> a=.a,{.y=.({:a)f"1}.y
>> a=.a,{.y=.({:a)f"1}.y
>> a=.a,{.y=.({:a)f"1}.y
>> a=.a,{.y=.({:a)f"1}.y
>> )
>> orto(!/~)i.10
>>1   1   1   11   1   1   1   1  1
>>   _9  _7  _5  _3   _1   1   3   5   7  9
>>6   2  _1  _3   _4  _4  _3  _1   2  6
>> _42  14  35  31   12 _12 _31 _35 _14 42
>>   18 _22 _17   3   18  18   3 _17 _22 18
>>   _6  14  _1 _11   _6   6  11   1 _14  6
>>3 _11  10   6   _8  _8   6  10 _11  3
>>   _9  47 _86  42   56 _56 _42  86 _47  9
>>1  _7  20 _28   14  14 _28  20  _7  1
>>   _1   9 _36  84 _126 126 _84  36  _9  1
>>
>>
>> How can the program orto be made less embarrassing?
>>
>> Thank you!
>>
>>
>> Bo.
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
> --
> Met vriendelijke groet,
> @@i = Arie Groeneveld
>
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] orthogonalizing a matrix

2014-09-16 Thread Raul Miller
Actually, thinking about this - the explicit version should be within a
factor of 2 of the performance of the power approach unless intermediate
results are so large you run out of memory.

Thanks,

-- 
Raul

On Tue, Sep 16, 2014 at 6:33 AM, Raul Miller  wrote:

> Here's another power iterator approach:
>
>{."2 ({. f"1 }.)^:(i.@#) !/~i.10
>
> And here's a looping explicit approach:
>
> orto=:3 :0
>   a=. 1 {. y
>   for. i.(#y)-1 do.
> a=.a,{.y=.({:a)f"1}.y
>   end.
> )
>
> The explicit approach should be more efficient on very large arguments,
> but has no advantage on a 10 by 10.
>
> Thanks,
>
> --
> Raul
>
> On Tue, Sep 16, 2014 at 4:46 AM, Aai  wrote:
>
>> I'm not sure if this is less embarrassing, but here's an power iterator
>> solution:
>>
>> 0{::([ ((,{.);]) {:@[ f"1 }.@])&>/^:(<:@#`(,:@{.;])) !/~i.10
>>
>>
>>
>> On 16-09-14 08:56, 'Bo Jacoby' via Programming wrote:
>>
>>> I managed to ortogonalize a 10 10 - matrix like this:
>>>
>>> f=.[:(%+./)(]*[:+/[*[)-[*[:+/*
>>> orto =. 3 : 0
>>> a=.,:{.y
>>> a=.a,{.y=.({:a)f"1}.y
>>> a=.a,{.y=.({:a)f"1}.y
>>> a=.a,{.y=.({:a)f"1}.y
>>> a=.a,{.y=.({:a)f"1}.y
>>> a=.a,{.y=.({:a)f"1}.y
>>> a=.a,{.y=.({:a)f"1}.y
>>> a=.a,{.y=.({:a)f"1}.y
>>> a=.a,{.y=.({:a)f"1}.y
>>> a=.a,{.y=.({:a)f"1}.y
>>> )
>>> orto(!/~)i.10
>>>1   1   1   11   1   1   1   1  1
>>>   _9  _7  _5  _3   _1   1   3   5   7  9
>>>6   2  _1  _3   _4  _4  _3  _1   2  6
>>> _42  14  35  31   12 _12 _31 _35 _14 42
>>>   18 _22 _17   3   18  18   3 _17 _22 18
>>>   _6  14  _1 _11   _6   6  11   1 _14  6
>>>3 _11  10   6   _8  _8   6  10 _11  3
>>>   _9  47 _86  42   56 _56 _42  86 _47  9
>>>1  _7  20 _28   14  14 _28  20  _7  1
>>>   _1   9 _36  84 _126 126 _84  36  _9  1
>>>
>>>
>>> How can the program orto be made less embarrassing?
>>>
>>> Thank you!
>>>
>>>
>>> Bo.
>>> --
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>
>>
>> --
>> Met vriendelijke groet,
>> @@i = Arie Groeneveld
>>
>>
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] orthogonalizing a matrix

2014-09-16 Thread Raul Miller
I was seeing factor of 2 variation in timing:

   timespacex '0{::([ ((,{.);]) {:@[ f"1 }.@])&>/^:(<:@#`(,:@{.;])) !/~i.10'
0.000502896 22400
   timespacex '{."2 ({. f"1 }.)^:(i.@#) !/~i.10'
0.000670315 29696
   timespacex '{."2 ({. f"1 }.)^:(i.@#) !/~i.10'
0.00038519 29696
   timespacex '{."2 ({. f"1 }.)^:(i.@#) !/~i.10'
0.000499689 29696
   timespacex '0{::([ ((,{.);]) {:@[ f"1 }.@])&>/^:(<:@#`(,:@{.;])) !/~i.10'
0.000622527 22400
   timespacex '0{::([ ((,{.);]) {:@[ f"1 }.@])&>/^:(<:@#`(,:@{.;])) !/~i.10'
0.00041149 22400
   timespacex '0{::([ ((,{.);]) {:@[ f"1 }.@])&>/^:(<:@#`(,:@{.;])) !/~i.10'
0.000336119 22400
   timespacex 'orto !/~i.10'
0.000570569 15488
   timespacex 'orto !/~i.10'
0.000490067 15488
   timespacex 'orto !/~i.10'
0.000500651 15488
   timespacex 'orto !/~i.10'
0.000341251 15488
   timespacex 'orto !/~i.10'
0.000459598 15488
   timespacex 'orto !/~i.10'
0.000625413 15488
   timespacex 'orto !/~i.10'
0.000621244 15488

So anything less than a factor of 2 is roughly equivalent.

Thanks,

-- 
Raul

On Tue, Sep 16, 2014 at 7:02 AM, Aai  wrote:

>    timer '{."2 ({. f"1 }.)^:(i.@#) !/~i.150'
> 1.63711
>
>timer 'P=.{.S:0 }:({. f"1 }.)&.>^:a:  1.44146
>
>timer 'Q=.orto !/~i.150'
> 1.43562
>
>P-:Q
> 1
>
> Probably still small matrices ;-)
>
>
>
>
> On 16-09-14 12:45, Raul Miller wrote:
>
>> Actually, thinking about this - the explicit version should be within a
>> factor of 2 of the performance of the power approach unless intermediate
>> results are so large you run out of memory.
>>
>> Thanks,
>>
>>
> --
> Met vriendelijke groet,
> @@i = Arie Groeneveld
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] debugging with rank

2014-09-16 Thread Raul Miller
demofn1=:3 :0
  X=. i. 10
  Y=. demofn2"0 X
)

demofn2=:3 :0
  a=.y+1
  b=.2*a
)

13!:0]1
13!:3'demofn2 1'
demofn1''
|stop: demofn2
|   b=.2*a
|demofn2[1]
  13!:19''
|stop: demofn2
|   b=.2*a
|demofn2[1]
  13!:19''
|stop: demofn2
|   b=.2*a
|demofn2[1]
  13!:19''
|stop: demofn2
|   b=.2*a
|demofn2[1]
  13!:19''
|stop: demofn2
...

How does one break out of a rank statement in the calling verb, when using
a low rank function on a large array?

Thanks,

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


Re: [Jprogramming] orthogonalizing a matrix

2014-09-16 Thread Raul Miller
Thank you.

But my approach was not really suitable for use as a tacit verb.

Probably I should have instead done this:

   0 {"2 ({. f"1 }.)^:(i.@#) !/~i.10

because

   (0 {"2 ({. f"1 }.)^:(i.@#)) !/~i.10

gives the same result.

Thanks,

-- 
Raul

On Tue, Sep 16, 2014 at 7:18 AM, Aai  wrote:

> BTW your solution is beautiful in all its simplicity :-)
>
>
> On 16-09-14 13:06, Raul Miller wrote:
>
>> I was seeing factor of 2 variation in timing:
>>
>> timespacex '0{::([ ((,{.);]) {:@[ f"1 }.@])&>/^:(<:@#`(,:@{.;]))
>> !/~i.10'
>> 0.000502896 22400
>> timespacex '{."2 ({. f"1 }.)^:(i.@#) !/~i.10'
>> 0.000670315 29696
>> timespacex '{."2 ({. f"1 }.)^:(i.@#) !/~i.10'
>> 0.00038519 29696
>> timespacex '{."2 ({. f"1 }.)^:(i.@#) !/~i.10'
>> 0.000499689 29696
>> timespacex '0{::([ ((,{.);]) {:@[ f"1 }.@])&>/^:(<:@#`(,:@{.;]))
>> !/~i.10'
>> 0.000622527 22400
>> timespacex '0{::([ ((,{.);]) {:@[ f"1 }.@])&>/^:(<:@#`(,:@{.;]))
>> !/~i.10'
>> 0.00041149 22400
>> timespacex '0{::([ ((,{.);]) {:@[ f"1 }.@])&>/^:(<:@#`(,:@{.;]))
>> !/~i.10'
>> 0.000336119 22400
>> timespacex 'orto !/~i.10'
>> 0.000570569 15488
>> timespacex 'orto !/~i.10'
>> 0.000490067 15488
>> timespacex 'orto !/~i.10'
>> 0.000500651 15488
>> timespacex 'orto !/~i.10'
>> 0.000341251 15488
>> timespacex 'orto !/~i.10'
>> 0.000459598 15488
>> timespacex 'orto !/~i.10'
>> 0.000625413 15488
>> timespacex 'orto !/~i.10'
>> 0.000621244 15488
>>
>> So anything less than a factor of 2 is roughly equivalent.
>>
>> Thanks,
>>
>>
> --
> Met vriendelijke groet,
> @@i = Arie Groeneveld
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] OOJ and calling a verb from another locale

2014-09-17 Thread Raul Miller
Out of curiosity, why?

Thanks,

-- 
Raul

On Wed, Sep 17, 2014 at 2:21 AM, Jon Hough  wrote:
> Thanks for the answers.
> I think I was trying to be a little too clever. But for my specific problem 
> OOP is the way to go I think.
>
>
> --- Original Message ---
>
> From: "Dan Bron" 
> Sent: September 16, 2014 4:47 AM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>
> If this was StackOverflow, I'd be able to give this post a +1. As it is,
> however, the best I can do is clutter up the list by vehemently agreeing
> with you :)
>
> -Dan
>
> - Original Message ---
>
> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>From: Devon McCormick 
>Date: Mon, 15 Sep 2014 15:38:37 -0400
>  To: J-programming forum 
>
> The basic problem is attempting to do OO for its own sake.
>
> On Mon, Sep 15, 2014 at 2:32 PM, Raul Miller  wrote:
>
>> I can see two things you are doing wrong here, perhaps three.
>>
>> First, consider:
>>
>>myVerb=: +/ % #
>>MyVerb 1 2 3
>> |value error
>>
>> J is case sensitive.
>>
>> Next, consider:
>>coname''
>> base
>>myVerb_base_
>> +/ % #
>>myVerb_z_
>> |value error
>>
>> You defined myVerb in the base locale, and not in the z locale.
>>
>> So that's two things.
>>
>> Next let's consider the design of your constructor:
>>
>> coclass 'MyClass'
>>
>> create=: verb define
>>   myValue=: ".y
>> )
>>
>> This says that you are expecting the constructor to be getting an sentence
>> which will be evaluated in the object's locale. That means that any names
>> would have to be defined in the z locale or in your class definition
>> definition (by default your object inherits from z and the class but not
>> from any other locale). So that's the possible third problem.
>>
>> You might instead want the object to inherit from some other locale (in
>> this example, you have implied you are interested in the base locale). You
>> could make the class inherit from base:
>>
>> coclass 'MyClass'
>> coinsert 'base'
>>
>> create=: verb define
>>   myValue=: ".y
>> )
>>
>> Or maybe you think that that is a bad idea, and instead only want the
>> sentence to be evaluated in the base locale:
>>
>> coclass 'MyClass'
>>
>> create=: verb define
>>   myValue=: do_base_ y
>> )
>>
>> (There is no way to discover what locale you were called from unless
>> debugging was enabled before the call was made, or unless some
>> programmer-imposed convention was used to identify the calling locale.)
>>
>> Of course, you could just specify the locale where the name was defined in
>> the sentence you pass to the constructor:
>>
>>'myVerb_base_ 1 2 3' conew 'MyClass'
>> +-+
>> |5|
>> +-+
>>myValue_5_
>> 2
>>
>> I'd also take note of the other responses you've gotten.
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>>
>>
>>
>>
>> On Mon, Sep 15, 2014 at 10:38 AM, Jon Hough  wrote:
>>
>> > OOJ = object oriented J
>> > I have a preexisting verb, for example lets call it myVerb =. +/ % #.
>> > Next I define a class:
>> > coclass 'MyClass'
>> > create =: verb define   myValue =: ". y
>> > )
>> > So, essentialy my value is going to run the command y, using verb ".
>> > So perhaps I want y to by 'myVerb 1 2 3'
>> > Then, hopefully myValue will be 2.
>> > So I do
>> > myObj =: conew 'MyClass'
>> > create__myObj 'MyVerb 1 2 3'
>> > However, I get a value error for MyVerb. I asusme this is because myVerb
>> > was defined in a different locale.
>> > I then tried create__myObj 'MyVerb_z_ 1 2 3'
>> > Which also gives a value error.
>> > By the way, what I am trying to do is pass a callback to the constructor
>> > of MyClass, so I can execute an arbitrary function. I am using ". to call
>> > the arbitrary function. I think this method of callbacks was shown in J
>> for
>> > C.
>> > So the question is, what is my code doing wrong?
>> > Thanks.
>> >
>> >
>> > --
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> >
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
>
>
> --
> Devon McCormick, CFA
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] OOJ and calling a verb from another locale

2014-09-17 Thread Raul Miller
Using a class (or a locale) is indeed a way of tying variables together.

Another approach (which is all a class or an object "really is", in J)
is to adopt a naming convention. Names can be thought of as
references. (Indices can also be thought of as references, but they
are more regular in their behavior than names).

The risk, with classes and objects, is that you'll be creating
something you don't really understand and whose behavior will be
mysterious to you as a result. It's somewhat like the snakeoil
approach to medicine (which, granted, has some benefits, even if they
are only placebo or "fun-oriented").

And, I guess it might be something of a "what else are you going to
do" kind of thing. But that's why I asked.

Thanks,

-- 
Raul


On Wed, Sep 17, 2014 at 3:45 AM, Jon Hough  wrote:
> Because I am making objects whose instance variables are dependent on the 
> constructor.
> I could use inheritence but the number of subclasses will get very large. So 
> I originally thought just define the variables based on what is passed in the 
> constructor.
> That way I only need one class.
> Why do I need a class?
> Well, maybe I don't. But I have half a dozen variables I want to tie 
> together. For me the obvious choice (in Java, C++ for example) is to make a 
> class.
>
>
> --- Original Message ---
>
> From: "Raul Miller" 
> Sent: September 17, 2014 4:37 PM
> To: "Programming forum" 
> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>
> Out of curiosity, why?
>
> Thanks,
>
> --
> Raul
>
> On Wed, Sep 17, 2014 at 2:21 AM, Jon Hough  wrote:
>> Thanks for the answers.
>> I think I was trying to be a little too clever. But for my specific problem 
>> OOP is the way to go I think.
>>
>>
>> --- Original Message ---
>>
>> From: "Dan Bron" 
>> Sent: September 16, 2014 4:47 AM
>> To: programm...@jsoftware.com
>> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>>
>> If this was StackOverflow, I'd be able to give this post a +1. As it is,
>> however, the best I can do is clutter up the list by vehemently agreeing
>> with you :)
>>
>> -Dan
>>
>> - Original Message ---
>>
>> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>>From: Devon McCormick 
>>Date: Mon, 15 Sep 2014 15:38:37 -0400
>>  To: J-programming forum 
>>
>> The basic problem is attempting to do OO for its own sake.
>>
>> On Mon, Sep 15, 2014 at 2:32 PM, Raul Miller  wrote:
>>
>>> I can see two things you are doing wrong here, perhaps three.
>>>
>>> First, consider:
>>>
>>>myVerb=: +/ % #
>>>MyVerb 1 2 3
>>> |value error
>>>
>>> J is case sensitive.
>>>
>>> Next, consider:
>>>coname''
>>> base
>>>myVerb_base_
>>> +/ % #
>>>myVerb_z_
>>> |value error
>>>
>>> You defined myVerb in the base locale, and not in the z locale.
>>>
>>> So that's two things.
>>>
>>> Next let's consider the design of your constructor:
>>>
>>> coclass 'MyClass'
>>>
>>> create=: verb define
>>>   myValue=: ".y
>>> )
>>>
>>> This says that you are expecting the constructor to be getting an sentence
>>> which will be evaluated in the object's locale. That means that any names
>>> would have to be defined in the z locale or in your class definition
>>> definition (by default your object inherits from z and the class but not
>>> from any other locale). So that's the possible third problem.
>>>
>>> You might instead want the object to inherit from some other locale (in
>>> this example, you have implied you are interested in the base locale). You
>>> could make the class inherit from base:
>>>
>>> coclass 'MyClass'
>>> coinsert 'base'
>>>
>>> create=: verb define
>>>   myValue=: ".y
>>> )
>>>
>>> Or maybe you think that that is a bad idea, and instead only want the
>>> sentence to be evaluated in the base locale:
>>>
>>> coclass 'MyClass'
>>>
>>> create=: verb define
>>>   myValue=: do_base_ y
>>> )
>>>
>>> (There is no way to discover what locale you were called from unless
>>> debugging was enabled before the call was made, or unless so

Re: [Jprogramming] LZ77

2014-09-17 Thread Raul Miller
I would ignore the stuff about "hashes" and "hash chains" and "singly
linked". Hashes are nice sometimes but other times they're just a
disaster. Sometimes that's better than the alternative, but their
marketing is sometimes significantly better than their actual
behavior.

Anyways, what's really happening here is an exact match search and
some kind of constraint on the size of the table.

I think the best way to approach that in J is to search in sorted
lists. The problem here is the incremental update. You don't want to
re-sort a large list every time you add something to the list.

The way to approach that, I think, is to have several generations of
lists, with each larger than the last, and each slower to be update
than the last.

So, for example, have on list which is unsorted. Use i. to look things
up in it, and merge it into the next list when it gets too long (maybe
when it has 30 items in it).

The next list gets sorted every time it gets stuff added to it. Use I.
to look things up in it. Merge it into the next list when it gets too
long (maybe when it has 1000 items in it).

Same for the next list, but this one, when it gets too long, you
arbitrarily discard items from it.

Now the other thing that's happening, here, is that J doesn't really
do all that well with incremental update algorithms. You'll still be
slow if you do things "one group of three" at a time. But -
hypothetically at least - you don't have to. The ideal would be to
come up with an algorithm for a block of text which complies (at least
in terms of data structures) with the rfc and which behaves reasonably
close to the behavior of the rfc described behavior.

But having a slow implementation that works is a really important
step. That (with some test cases - like the one you described here)
gives you a baseline to test against.

Hopefully this helps?

Thanks,

-- 
Raul




On Wed, Sep 17, 2014 at 5:23 AM, bill lam  wrote:
> The LZ77 variation used in deflate is at the bottom (copied from rfc
> 1951).  I tried to translate it into J using a hash function which
> interprets XYZ as the lower 3 bytes of a 4 byte integer.  My J
> implementation worked but efficient is rather poor.  I think the
> inefficiency of my implementation came from the need to
> 1. build a vector of pre-computed hash of size equal to sliding
> window. (although the hash of all bytes had been pre-computed)
> 2. find the last index of the hash of current XYZ in the vector.
> (since the left argument changes, special code of the form m&i: does not 
> apply)
>
> If data are truly random, the chance of matching would be very small,
> thus the time spent should roughly the sum of the above 1 & 2 for
> every byte, however it took a very long time even for data size of
> only about 500KB.  Any idea for a better J implementation.
>
> NB. for deflate, minimum length for match is 3, max length is 285,
> maximum distance is 32K.
>
> eg. LZ77 compression of the input 500#'abc'
> is
> aa(285,1)(213,1)b(285,1)(214,1)c(285,1)(214,1)
>
> inside each bracket is (length,distance) pair applied to the  history
> buffer. Untested but should be something like this.
>
> (text from rfc)
> The compressor uses a chained hash table to find duplicated strings,
>using a hash function that operates on 3-byte sequences.  At any
>given point during compression, let XYZ be the next 3 input bytes to
>be examined (not necessarily all different, of course).  First, the
>compressor examines the hash chain for XYZ.  If the chain is empty,
>the compressor simply writes out X as a literal byte and advances one
>byte in the input.  If the hash chain is not empty, indicating that
>the sequence XYZ (or, if we are unlucky, some other 3 bytes with the
>same hash function value) has occurred recently, the compressor
>compares all strings on the XYZ hash chain with the actual input data
>sequence starting at the current point, and selects the longest
>match.
>
>The compressor searches the hash chains starting with the most recent
>strings, to favor small distances and thus take advantage of the
>Huffman encoding.  The hash chains are singly linked. There are no
>deletions from the hash chains; the algorithm simply discards matches
>that are too old.  To avoid a worst-case situation, very long hash
>chains are arbitrarily truncated at a certain length, determined by a
>run-time parameter.
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] OOJ and calling a verb from another locale

2014-09-17 Thread Raul Miller
On Wed, Sep 17, 2014 at 11:30 AM, 'Pascal Jasmin' via Programming
 wrote:
> A class approach to problem solving is a very useful organization
> structure for dealing with the normal case that you are unsure how
> to solve the problem (or the problem is likely to be redefined
> perhaps by yourself as you go).

Exactly.

This is why it's always a good idea to ask what problem is being
solved, whenever someone is advocating classes.

It's often the case that (a) they do not know, and (b) that they would
benefit from thinking and talking about this issue.

Note also that one can replace the word "class" with "machine" with
essentially no loss in meaning.

Thanks,

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


Re: [Jprogramming] OOJ and calling a verb from another locale

2014-09-17 Thread Raul Miller
Reading that article, I stall when you say

"Even if they are defined with 1 : or 2 : , the first 2 types of
modifiers should be considered tacit,"

I do not know what you are referring to by the phrase "the first 2
types of modifiers". Do you mean "the first 2 types of adverbs (or
conjunctions)" or are you referring to nounconj and nounconj2? If  the
latter, I think the statement is erroneous. If the former, I'm a bit
dubious about the distinction.

The concept of tacit is slippery enough that it's probably worth
quoting the definition you are using, and describing what it is about
the context  that makes "tacit" a relevant concept whenever we talk
about it.

Anyways, I got stuck there, and I thought you should know.

Thanks,

-- 
Raul

On Wed, Sep 17, 2014 at 12:54 PM, 'Pascal Jasmin' via Programming
 wrote:
> You may find this article helpful:  
> http://www.jsoftware.com/jwiki/PascalJasmin/3%20types%20of%20adverbs%20conjunctions%20and%20binding
>
> These are indeed issues you understand by surprise (why is this code not 
> doing what I meant it to do) comming from other languages.
>
>
> - Original Message -
> From: Brian Schott 
> To: Programming forum 
> Cc:
> Sent: Wednesday, September 17, 2014 12:05 PM
> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>
> Pascal,
>
> I especially liked the point you made below. I think such a point would be
> very appreciated by new J programmers and may not be well known.
>
>
>
>
> "... In J, the verb  (2 + myvar"_) will produce a constant verb based on
> the value of myvar at definition, while (2 + 3 : 'myvar') will obtain the
> latest value of myvar. ..."
>
>
>
>
> --
> (B=)
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] OOJ and calling a verb from another locale

2014-09-17 Thread Raul Miller
Well... http://jsoftware.com/help/primer/tacit_definition.htm defines
tacit as "In a tacit definition the arguments are not named and do not
appear explicitly in the definition." (It also needs to be updated to
use x and y instead of x. and y. when referring to the arguments of an
explicit definition. Though I really wish that that whole migration of
argument names had been done more gradually... Actually, given that it
was purely for the convenience of OO coding, I'm sort of wondering if
it was even a good idea in the first place. Oh well... nothing is
perfect.)

So when you say 1 : 'a u ]' returns a probably tacit verb, you are not
really saying that 1 :'a u ]' is tacit. Instead, you are saying that u
is probably tacit, and that a is probably tacit.

But that does not mean that 1 :'a u ]' is tacit.

But I do agree that the locale and timing difference for resolving the
definition of 'a' is worth calling out.

And I do appreciate your use of the word modifiers - but it probably
deserves a mention where you use it in your essay?

As for this:

   a_t_=: 2
   a_base_=: 6
   cocurrent 'base'
   +: a2_t_=: 1 :'u a'
12
   +: a2_t_
4

The issue here, I think, is that we did not use the name a2_t_ to find
the definition we used to calculate the value 12. We set a2_t_ to that
value, but that's just a side effect.

If expected
   +: a2_t_=: 1 :'u a'
4
that would have some confusing implications.

In particular, it would mean that we would expect this:
   a1_t_=: a2_t_=: a3_t_=: 1 :'u a'
   a1_t_
a2_t_
   a2_t_
a3_t_
   a3_t_
1 :'u a'

What we have, instead, is simpler and easier to reason about:
   a1_t_=: a2_t_=: a3_t_=: 1 :'u a'
   a1_t_
1 :'u a'
   a2 _t_
1 :'u a'
   a3_t_
1 :'u a'

In other words, the current design is that if we assign the same value
to several names they all get the same value. I am comfortable
thinking of that as "not a bug".

Thanks,

-- 
Raul


On Wed, Sep 17, 2014 at 3:10 PM, 'Pascal Jasmin' via Programming
 wrote:
> 1 : 'a u ]'  is adverb that returns an anonymous and probably tacit verb.  I 
> say "probably" because u could be explicit, but the term tacit still seems 
> appropriate to describe the overall expression.
>
> 1 : 'a u y' is an adverb that executes its explicit definition in the 
> caller's locale.  It could be stated as it is not evaluated until it is 
> passed y, or it is bound with its unsubstituted definition.
>
> In the first example, a will be evaluated (and substituted with a constant) 
> in the adverb's locale.  In the second, a will be evaluated in the caller's 
> locale.  So, IMO, its worth calling these 2 different types of adverbs.  
> Something purely tacit such as @] is still like the first type of adverb
>
> I use the term modifiers, because this distinction applies equally to 
> conjunctions.
>
> conj_t_ =: 2 : 'a + v + u '
> conjE_t_ =: 2 : 'v + u  +a + y'
>
>+: conj_t_ +:
> 2 + +: + +:
>+: conjE_t_ +:
>
> +: (2 : 'v + u  +a + y') +:  NB. what is returned no longer has any reference 
> to t locale.
>
> I understand the nounconj reference makes for a distraction on a seldom 
> considered topic, but it seems like a separate enough type of modifier
>
>a2_t_ =: 1 : 'u a'
>+: a2_t_
> 4   NB. returns noun
>
>+: 1 : 'u a [y'
> +: (1 : 'u a [y')  NB. returns verb phrase that will be parsed/executed and 
> use a in base/caller
>
> the following seems like a bug to me,
>
>a =: 6  NB. in base
>+:  a2_t_ =: 1 : 'u a'  NB. seems to pre-optimize to get a from base.  
> Though behaviour is correct if defined on separate line in base.
> 12
>
>erase 'a'
> 1
>+:  (a2_t_ =: 1 : 'u a')
>
> +: a
>
>
> - Original Message -
> From: Raul Miller 
> To: Programming forum 
> Cc:
> Sent: Wednesday, September 17, 2014 2:00 PM
> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>
> Reading that article, I stall when you say
>
> "Even if they are defined with 1 : or 2 : , the first 2 types of
> modifiers should be considered tacit,"
>
> I do not know what you are referring to by the phrase "the first 2
> types of modifiers". Do you mean "the first 2 types of adverbs (or
> conjunctions)" or are you referring to nounconj and nounconj2? If  the
> latter, I think the statement is erroneous. If the former, I'm a bit
> dubious about the distinction.
>
> The concept of tacit is slippery enough that it's probably worth
> quoting the definition you are using, and desc

Re: [Jprogramming] OOJ and calling a verb from another locale

2014-09-17 Thread Raul Miller
Hmm...

Usually when I want a clean slate, I start J over again.

This way, if I need something, that I forgot to put in the script, I
can pull it out of the old J. And then I can shut it down when my
tests are working well enough.

This works better with jqt than with jhs.

And you are right - I doubt many children would find interesting most
of the things I play with. Actually, that's probably true of most
people.

Thanks,

-- 
Raul

On Wed, Sep 17, 2014 at 10:59 PM, Linda Alvord  wrote:
> Raul,  My way of thinking about J is as a form of dialog.  As I enter I use
> varialble on the fly.  A=:  allows me to use A until I change it's value.
> However often I just want to get rid of it.  Often I keep scripts of the
> sentences I am using to develop an idea.  When I am ready to use the scrip
> entirely I erase all names that I have used and get a bunch of ones.  I
> assume that it has erased all the names I have used.  However in this
> insance, as in most I have no interest in other locales. And have never seen
> a need to erase them anyway.
>
> So I have assigned names to images or in some cases have not assigned names
> to them.  What is happening is that If I use a C in one script and then a C
> in another script I don't get the image that agrees with the new data in the
> new script.
>
> In my simplistic way of thinking about the old image is that it must be on a
> clipboard somewhere. If running a new script could get rid of the old images
> that are hidden somewhere?
>
> I can see many ways for young children to make an study images that will
> teach them many things about tables and arrays. However, the suggestions
> about cache and some of your suggestions would be stumbling blocks to
> simplicidty.
>
> I may be naïve but it seems like a housekeeping chore that J could be good
> at.
>
> Linda
>
> -Original Message-
> From: programming-boun...@forums.jsoftware.com
> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Raul Miller
> Sent: Wednesday, September 17, 2014 2:01 PM
> To: Programming forum
> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>
> Reading that article, I stall when you say
>
> "Even if they are defined with 1 : or 2 : , the first 2 types of
> modifiers should be considered tacit,"
>
> I do not know what you are referring to by the phrase "the first 2
> types of modifiers". Do you mean "the first 2 types of adverbs (or
> conjunctions)" or are you referring to nounconj and nounconj2? If  the
> latter, I think the statement is erroneous. If the former, I'm a bit
> dubious about the distinction.
>
> The concept of tacit is slippery enough that it's probably worth
> quoting the definition you are using, and describing what it is about
> the context  that makes "tacit" a relevant concept whenever we talk
> about it.
>
> Anyways, I got stuck there, and I thought you should know.
>
> Thanks,
>
> --
> Raul
>
> On Wed, Sep 17, 2014 at 12:54 PM, 'Pascal Jasmin' via Programming
>  wrote:
>> You may find this article helpful:
> http://www.jsoftware.com/jwiki/PascalJasmin/3%20types%20of%20adverbs%20conju
> nctions%20and%20binding
>>
>> These are indeed issues you understand by surprise (why is this code not
> doing what I meant it to do) comming from other languages.
>>
>>
>> - Original Message -
>> From: Brian Schott 
>> To: Programming forum 
>> Cc:
>> Sent: Wednesday, September 17, 2014 12:05 PM
>> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>>
>> Pascal,
>>
>> I especially liked the point you made below. I think such a point would be
>> very appreciated by new J programmers and may not be well known.
>>
>>
>>
>>
>> "... In J, the verb  (2 + myvar"_) will produce a constant verb based on
>> the value of myvar at definition, while (2 + 3 : 'myvar') will obtain the
>> latest value of myvar. ..."
>>
>>
>>
>>
>> --
>> (B=)
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] OOJ and calling a verb from another locale

2014-09-17 Thread Raul Miller
Maybe Oleg's post, here?

http://www.jsoftware.com/pipermail/programming/2006-March/001568.html

Or Ric's post, here?

http://www.jsoftware.com/pipermail/programming/2009-May/014605.html

I'm not sure if I've ever advocated that approach, but it does sound
like a good idea.

Thanks,

-- 
Raul

On Thu, Sep 18, 2014 at 12:48 AM, robert therriault
 wrote:
> Raul, (and Linda)
>
> I thought it was you (but it may also have been Ric Sherlock or Oleg 
> Kobchenko) that showed me the trick of putting
>
> coerase <'localename'  NB. erases the entire locale  (18!:55)
>
> at the top of my script and then following with
>
> cocurrent 'localename'  NB. coclass also works identically (18!:4@boxxopen)
>
> so that all subsequent declarations are in the localename locale
>
> Each time you run the script the locale is destroyed and then rebuilt 
> according to the contents of the script. A variable that is removed from the 
> script disappears the next time you run because it is not put back in. I find 
> that this helps control the ghosts in the machine most of the time. The 
> exceptions are when I am playing between locales, but I usually run my brain 
> through the locales lab one more time and that usually sorts things as I 
> unmuddle my confusion.
>
> Cheers, bob
>
>
> On Sep 17, 2014, at 8:22 PM, Raul Miller  wrote:
>
>> Hmm...
>>
>> Usually when I want a clean slate, I start J over again.
>>
>> This way, if I need something, that I forgot to put in the script, I
>> can pull it out of the old J. And then I can shut it down when my
>> tests are working well enough.
>>
>> This works better with jqt than with jhs.
>>
>> And you are right - I doubt many children would find interesting most
>> of the things I play with. Actually, that's probably true of most
>> people.
>>
>> Thanks,
>>
>> --
>> Raul
>>
>> On Wed, Sep 17, 2014 at 10:59 PM, Linda Alvord  
>> wrote:
>>> Raul,  My way of thinking about J is as a form of dialog.  As I enter I use
>>> varialble on the fly.  A=:  allows me to use A until I change it's value.
>>> However often I just want to get rid of it.  Often I keep scripts of the
>>> sentences I am using to develop an idea.  When I am ready to use the scrip
>>> entirely I erase all names that I have used and get a bunch of ones.  I
>>> assume that it has erased all the names I have used.  However in this
>>> insance, as in most I have no interest in other locales. And have never seen
>>> a need to erase them anyway.
>>>
>>> So I have assigned names to images or in some cases have not assigned names
>>> to them.  What is happening is that If I use a C in one script and then a C
>>> in another script I don't get the image that agrees with the new data in the
>>> new script.
>>>
>>> In my simplistic way of thinking about the old image is that it must be on a
>>> clipboard somewhere. If running a new script could get rid of the old images
>>> that are hidden somewhere?
>>>
>>> I can see many ways for young children to make an study images that will
>>> teach them many things about tables and arrays. However, the suggestions
>>> about cache and some of your suggestions would be stumbling blocks to
>>> simplicidty.
>>>
>>> I may be naïve but it seems like a housekeeping chore that J could be good
>>> at.
>>>
>>> Linda
>>>
>>> -Original Message-
>>> From: programming-boun...@forums.jsoftware.com
>>> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Raul Miller
>>> Sent: Wednesday, September 17, 2014 2:01 PM
>>> To: Programming forum
>>> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>>>
>>> Reading that article, I stall when you say
>>>
>>> "Even if they are defined with 1 : or 2 : , the first 2 types of
>>> modifiers should be considered tacit,"
>>>
>>> I do not know what you are referring to by the phrase "the first 2
>>> types of modifiers". Do you mean "the first 2 types of adverbs (or
>>> conjunctions)" or are you referring to nounconj and nounconj2? If  the
>>> latter, I think the statement is erroneous. If the former, I'm a bit
>>> dubious about the distinction.
>>>
>>> The concept of tacit is slippery enough that it's probably worth
>>> quoting the definition you are using, and describing what it is about
>>> the context  that m

Re: [Jprogramming] LZ77

2014-09-18 Thread Raul Miller
I can try taking a look at the code, one of these days, if you want me to.

(Not right this second though.)

Thanks,

-- 
Raul


On Thu, Sep 18, 2014 at 5:45 AM, bill lam  wrote:
> Thanks Raul,
>
> I followed you suggestion to use 2 generations of hash vector,
> Its speed is faster now although still far behind zlib.so.
>
> Ср, 17 сен 2014, Raul Miller написал(а):
>> I would ignore the stuff about "hashes" and "hash chains" and "singly
>> linked". Hashes are nice sometimes but other times they're just a
>> disaster. Sometimes that's better than the alternative, but their
>> marketing is sometimes significantly better than their actual
>> behavior.
>>
>> Anyways, what's really happening here is an exact match search and
>> some kind of constraint on the size of the table.
>>
>> I think the best way to approach that in J is to search in sorted
>> lists. The problem here is the incremental update. You don't want to
>> re-sort a large list every time you add something to the list.
>>
>> The way to approach that, I think, is to have several generations of
>> lists, with each larger than the last, and each slower to be update
>> than the last.
>>
>> So, for example, have on list which is unsorted. Use i. to look things
>> up in it, and merge it into the next list when it gets too long (maybe
>> when it has 30 items in it).
>>
>> The next list gets sorted every time it gets stuff added to it. Use I.
>> to look things up in it. Merge it into the next list when it gets too
>> long (maybe when it has 1000 items in it).
>>
>> Same for the next list, but this one, when it gets too long, you
>> arbitrarily discard items from it.
>>
>> Now the other thing that's happening, here, is that J doesn't really
>> do all that well with incremental update algorithms. You'll still be
>> slow if you do things "one group of three" at a time. But -
>> hypothetically at least - you don't have to. The ideal would be to
>> come up with an algorithm for a block of text which complies (at least
>> in terms of data structures) with the rfc and which behaves reasonably
>> close to the behavior of the rfc described behavior.
>>
>> But having a slow implementation that works is a really important
>> step. That (with some test cases - like the one you described here)
>> gives you a baseline to test against.
>>
>> Hopefully this helps?
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>>
>>
>> On Wed, Sep 17, 2014 at 5:23 AM, bill lam  wrote:
>> > The LZ77 variation used in deflate is at the bottom (copied from rfc
>> > 1951).  I tried to translate it into J using a hash function which
>> > interprets XYZ as the lower 3 bytes of a 4 byte integer.  My J
>> > implementation worked but efficient is rather poor.  I think the
>> > inefficiency of my implementation came from the need to
>> > 1. build a vector of pre-computed hash of size equal to sliding
>> > window. (although the hash of all bytes had been pre-computed)
>> > 2. find the last index of the hash of current XYZ in the vector.
>> > (since the left argument changes, special code of the form m&i: does not 
>> > apply)
>> >
>> > If data are truly random, the chance of matching would be very small,
>> > thus the time spent should roughly the sum of the above 1 & 2 for
>> > every byte, however it took a very long time even for data size of
>> > only about 500KB.  Any idea for a better J implementation.
>> >
>> > NB. for deflate, minimum length for match is 3, max length is 285,
>> > maximum distance is 32K.
>> >
>> > eg. LZ77 compression of the input 500#'abc'
>> > is
>> > aa(285,1)(213,1)b(285,1)(214,1)c(285,1)(214,1)
>> >
>> > inside each bracket is (length,distance) pair applied to the  history
>> > buffer. Untested but should be something like this.
>> >
>> > (text from rfc)
>> > The compressor uses a chained hash table to find duplicated strings,
>> >using a hash function that operates on 3-byte sequences.  At any
>> >given point during compression, let XYZ be the next 3 input bytes to
>> >be examined (not necessarily all different, of course).  First, the
>> >compressor examines the hash chain for XYZ.  If the chain is empty,
>> >the compressor simply writes out X as a literal byte and advances one
>> >byte in the input.  If the hash chain is not empty, indi

Re: [Jprogramming] LZ77

2014-09-18 Thread Raul Miller
It's unlikely that most of those patents have merit.

First, there's prior art (the LZ77 patent, for example - which is now
expired). And second, patents do not cover variations which would have
been obvious to someone with ordinary skill in the art before the
filing date of the patent.

In the context of a decompression routine written in J, anything
described by the LZ77 patent must be obvious in the context of patents
filed later. And, since J is a variant on APL, any approaches that
were obvious to APL programmers back in the day would also be
considered obvious (for example), but also anything published in prior
centuries could also be considered evidence for obviousness.

Changing the width of a window from 3 to 4? Obvious. Many grade school
kids are capable of doing that. Using an array instead of a linked
list? Obvious - that's what APL programmers do. Using an APL primitive
rather than some elaborate system of code? Obvious.

Anyways, if someone tries to sue us on patent grounds we have a lot of
options for how to respond. We could, for example, start a kickstarter
project to document sufficient prior art to refute the patent.
Probably the first step, though, would be to read the claims of the
asserted patents and see what we can find for prior art for any of the
relevant claims.

Generally speaking the claims will either be so narrow that they do
not apply, or so broad that they do apply but also apply to prior art.

And, generally speaking, the claims will be asserted by lawyers with
no background in coding and no understanding of what the claims mean.
They'll typically have "experts" who back them up, who are far less
competent - at least in the context of what's obvious to a J
programmer - than the typical J programmer.

Honestly, the biggest risk is probably falling asleep while reading
the legal "threats".

Thanks,

-- 
Raul



On Thu, Sep 18, 2014 at 6:09 AM, bill lam  wrote:
> Thanks. This is not urgent because zlib.so should usually
> available.
>
> Also as stated in rfc, many variation of LZ77 were patented so
> it suggested implementors to follow the guidelines (3 bytes at a
> time, hash etc) which is patent free.  If the improvement in
> speed is signaficant then we may ignore its guideline.  I guess
> there would not be any revenue in sueing Jsoftware for damage.
>
> Чт, 18 сен 2014, Raul Miller написал(а):
>> I can try taking a look at the code, one of these days, if you want me to.
>>
>> (Not right this second though.)
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Thu, Sep 18, 2014 at 5:45 AM, bill lam  wrote:
>> > Thanks Raul,
>> >
>> > I followed you suggestion to use 2 generations of hash vector,
>> > Its speed is faster now although still far behind zlib.so.
>> >
>> > Ср, 17 сен 2014, Raul Miller написал(а):
>> >> I would ignore the stuff about "hashes" and "hash chains" and "singly
>> >> linked". Hashes are nice sometimes but other times they're just a
>> >> disaster. Sometimes that's better than the alternative, but their
>> >> marketing is sometimes significantly better than their actual
>> >> behavior.
>> >>
>> >> Anyways, what's really happening here is an exact match search and
>> >> some kind of constraint on the size of the table.
>> >>
>> >> I think the best way to approach that in J is to search in sorted
>> >> lists. The problem here is the incremental update. You don't want to
>> >> re-sort a large list every time you add something to the list.
>> >>
>> >> The way to approach that, I think, is to have several generations of
>> >> lists, with each larger than the last, and each slower to be update
>> >> than the last.
>> >>
>> >> So, for example, have on list which is unsorted. Use i. to look things
>> >> up in it, and merge it into the next list when it gets too long (maybe
>> >> when it has 30 items in it).
>> >>
>> >> The next list gets sorted every time it gets stuff added to it. Use I.
>> >> to look things up in it. Merge it into the next list when it gets too
>> >> long (maybe when it has 1000 items in it).
>> >>
>> >> Same for the next list, but this one, when it gets too long, you
>> >> arbitrarily discard items from it.
>> >>
>> >> Now the other thing that's happening, here, is that J doesn't really
>> >> do all that well with incremental update algorithms. You'll still be
>> >> slow if you do things "one group of three" at a tim

Re: [Jprogramming] zlib huffman coding

2014-09-18 Thread Raul Miller
It would be interesting to review the code and your test cases, once
you are happy with it.

The whole "try again" thing is a good first cut, but there might be
other approaches. (Or there might not be.)

Thanks,

-- 
Raul


On Thu, Sep 18, 2014 at 5:58 AM, bill lam  wrote:
> After more tests, I found there is another rule not explicitly
> mentioned in rfc -- the maximum bit length is 15 (or 7 in another
> tree).  When the distribtution of frequency is highly spreaded,
> the maximnum from hcode can be 16. In this case, it needs to
> increase the level of (non-zero) minimum frequency and try
> again, and iterate until the maximum bit length is 15 or smaller.
>
> --
> regards,
> 
> GPG key 1024D/4434BAB3 2008-08-24
> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] LZ77

2014-09-18 Thread Raul Miller
Pun intended?

http://www.americanbar.org/aba.html

Thanks,

-- 
Raul


On Thu, Sep 18, 2014 at 11:22 AM, robert therriault
 wrote:
> The best form of self defence in a bar fight is to have left the bar 10 
> minutes before the fight starts. I learned that in Tai Chi and I think 
> software patent law is a lot like a bar fight. ;-)
>
> cheers, bob
>
> On Sep 18, 2014, at 8:11 AM, Raul Miller  wrote:
>
>> It's unlikely that most of those patents have merit.
>>
>> First, there's prior art (the LZ77 patent, for example - which is now
>> expired). And second, patents do not cover variations which would have
>> been obvious to someone with ordinary skill in the art before the
>> filing date of the patent.
>>
>> In the context of a decompression routine written in J, anything
>> described by the LZ77 patent must be obvious in the context of patents
>> filed later. And, since J is a variant on APL, any approaches that
>> were obvious to APL programmers back in the day would also be
>> considered obvious (for example), but also anything published in prior
>> centuries could also be considered evidence for obviousness.
>>
>> Changing the width of a window from 3 to 4? Obvious. Many grade school
>> kids are capable of doing that. Using an array instead of a linked
>> list? Obvious - that's what APL programmers do. Using an APL primitive
>> rather than some elaborate system of code? Obvious.
>>
>> Anyways, if someone tries to sue us on patent grounds we have a lot of
>> options for how to respond. We could, for example, start a kickstarter
>> project to document sufficient prior art to refute the patent.
>> Probably the first step, though, would be to read the claims of the
>> asserted patents and see what we can find for prior art for any of the
>> relevant claims.
>>
>> Generally speaking the claims will either be so narrow that they do
>> not apply, or so broad that they do apply but also apply to prior art.
>>
>> And, generally speaking, the claims will be asserted by lawyers with
>> no background in coding and no understanding of what the claims mean.
>> They'll typically have "experts" who back them up, who are far less
>> competent - at least in the context of what's obvious to a J
>> programmer - than the typical J programmer.
>>
>> Honestly, the biggest risk is probably falling asleep while reading
>> the legal "threats".
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>>
>> On Thu, Sep 18, 2014 at 6:09 AM, bill lam  wrote:
>>> Thanks. This is not urgent because zlib.so should usually
>>> available.
>>>
>>> Also as stated in rfc, many variation of LZ77 were patented so
>>> it suggested implementors to follow the guidelines (3 bytes at a
>>> time, hash etc) which is patent free.  If the improvement in
>>> speed is signaficant then we may ignore its guideline.  I guess
>>> there would not be any revenue in sueing Jsoftware for damage.
>>>
>>> Чт, 18 сен 2014, Raul Miller написал(а):
>>>> I can try taking a look at the code, one of these days, if you want me to.
>>>>
>>>> (Not right this second though.)
>>>>
>>>> Thanks,
>>>>
>>>> --
>>>> Raul
>>>>
>>>>
>>>> On Thu, Sep 18, 2014 at 5:45 AM, bill lam  wrote:
>>>>> Thanks Raul,
>>>>>
>>>>> I followed you suggestion to use 2 generations of hash vector,
>>>>> Its speed is faster now although still far behind zlib.so.
>>>>>
>>>>> Ср, 17 сен 2014, Raul Miller написал(а):
>>>>>> I would ignore the stuff about "hashes" and "hash chains" and "singly
>>>>>> linked". Hashes are nice sometimes but other times they're just a
>>>>>> disaster. Sometimes that's better than the alternative, but their
>>>>>> marketing is sometimes significantly better than their actual
>>>>>> behavior.
>>>>>>
>>>>>> Anyways, what's really happening here is an exact match search and
>>>>>> some kind of constraint on the size of the table.
>>>>>>
>>>>>> I think the best way to approach that in J is to search in sorted
>>>>>> lists. The problem here is the incremental update. You don't want to
>>>>>> re-sort a large list every time you add something to the list.
>>>>>>
>>>&g

Re: [Jprogramming] zlib huffman coding

2014-09-18 Thread Raul Miller
I see the attachment test script.

I added require'arc/zlib' to the top, and then ran it, and got an
error which probably means I need to do something different. But I am
not sure what.

Here's how it looks:

  13!:1''
|domain error
*cd[:0]
|zcompress2[0]
|   0=zcompress2 buf;len;y;(#y);x
|zlib_encode_so[0]
|   a-:zlib_decode_so`zlib_decode_j@.de b=.
zlib_encode_so`zlib_encode_j@.en a=.fread
jpath'~Public/arc/zlib/test/',y
|f2[:1]
|   0 0 f2'algorithm.txt'
|test[11]
|   test''
|[-100] c:\users\user\j64-803-user\temp\1.ijs
|   0!:0 y[4!:55<'y'
|   fn fl
|   0 load y
|   load'c:/users/user/j64-803-user/temp/1.ijs'

Thanks,

-- 
Raul


On Thu, Sep 18, 2014 at 11:42 AM, bill lam  wrote:
> IMO the huffman coding part is relatively easily and performance
> is acceptable, it looks like linear in time.
>
> the LZ77 is still very slow compared with zlib.so thus there
> should be room for improvement. Test caes are in public repos
> but not jal addons, I include here for your reference. Thanks.
>
> You may need ot modify some file path, you can replace the 4 or
> 5 text files with any other text files you like, so they are not
> attached.
>
> please let me know if the attachment test script is missing.
>
> After we are happy with zlib, we might try jpeg which is also a
> minefield of patents, unfortunately.
>
> Чт, 18 сен 2014, Raul Miller написал(а):
>> It would be interesting to review the code and your test cases, once
>> you are happy with it.
>>
>> The whole "try again" thing is a good first cut, but there might be
>> other approaches. (Or there might not be.)
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Thu, Sep 18, 2014 at 5:58 AM, bill lam  wrote:
>> > After more tests, I found there is another rule not explicitly
>> > mentioned in rfc -- the maximum bit length is 15 (or 7 in another
>> > tree).  When the distribtution of frequency is highly spreaded,
>> > the maximnum from hcode can be 16. In this case, it needs to
>> > increase the level of (non-zero) minimum frequency and try
>> > again, and iterate until the maximum bit length is 15 or smaller.
>> >
>> > --
>> > regards,
>> > 
>> > GPG key 1024D/4434BAB3 2008-08-24
>> > gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
>> > gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
>> > --
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> regards,
> 
> GPG key 1024D/4434BAB3 2008-08-24
> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] zlib huffman coding

2014-09-18 Thread Raul Miller
That's working.

Or I think it is - I'm waiting for the script to finish, as I type this.

This will obviously take some time.

Thanks,

-- 
Raul

On Thu, Sep 18, 2014 at 12:53 PM, bill lam  wrote:
> Yes it needs to require arc/zlib. Those text files not attached,
> also you need to change them , eg
>
>> zlib_encode_so`zlib_encode_j@.en a=.fread jpath'~Public/arc/zlib/test/',y
> to
>> zlib_encode_so`zlib_encode_j@.en a=.fread jpath'~temp/',y
>
> and put those file under your ~temp
>
> I attached the other text files for completeness. Please report
> if they are not attached and I'll send them off-list. Thanks.
>
> Also in f4, change the ~Addons to ~addons and check if you got
> those file, or try any other binary files you like. file size of
> 1MB should be more than enough because the J script zlib is
> quite slow.
>
> Чт, 18 сен 2014, Raul Miller написал(а):
>> I see the attachment test script.
>>
>> I added require'arc/zlib' to the top, and then ran it, and got an
>> error which probably means I need to do something different. But I am
>> not sure what.
>>
>> Here's how it looks:
>>
>>   13!:1''
>> |domain error
>> *cd[:0]
>> |zcompress2[0]
>> |   0=zcompress2 buf;len;y;(#y);x
>> |zlib_encode_so[0]
>> |   a-:zlib_decode_so`zlib_decode_j@.de b=.
>> zlib_encode_so`zlib_encode_j@.en a=.fread
>> jpath'~Public/arc/zlib/test/',y
>> |f2[:1]
>> |   0 0 f2'algorithm.txt'
>> |test[11]
>> |   test''
>> |[-100] c:\users\user\j64-803-user\temp\1.ijs
>> |   0!:0 y[4!:55<'y'
>> |   fn fl
>> |   0 load y
>> |   load'c:/users/user/j64-803-user/temp/1.ijs'
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Thu, Sep 18, 2014 at 11:42 AM, bill lam  wrote:
>> > IMO the huffman coding part is relatively easily and performance
>> > is acceptable, it looks like linear in time.
>> >
>> > the LZ77 is still very slow compared with zlib.so thus there
>> > should be room for improvement. Test caes are in public repos
>> > but not jal addons, I include here for your reference. Thanks.
>> >
>> > You may need ot modify some file path, you can replace the 4 or
>> > 5 text files with any other text files you like, so they are not
>> > attached.
>> >
>> > please let me know if the attachment test script is missing.
>> >
>> > After we are happy with zlib, we might try jpeg which is also a
>> > minefield of patents, unfortunately.
>> >
>> > Чт, 18 сен 2014, Raul Miller написал(а):
>> >> It would be interesting to review the code and your test cases, once
>> >> you are happy with it.
>> >>
>> >> The whole "try again" thing is a good first cut, but there might be
>> >> other approaches. (Or there might not be.)
>> >>
>> >> Thanks,
>> >>
>> >> --
>> >> Raul
>> >>
>> >>
>> >> On Thu, Sep 18, 2014 at 5:58 AM, bill lam  wrote:
>> >> > After more tests, I found there is another rule not explicitly
>> >> > mentioned in rfc -- the maximum bit length is 15 (or 7 in another
>> >> > tree).  When the distribtution of frequency is highly spreaded,
>> >> > the maximnum from hcode can be 16. In this case, it needs to
>> >> > increase the level of (non-zero) minimum frequency and try
>> >> > again, and iterate until the maximum bit length is 15 or smaller.
>> >> >
>> >> > --
>> >> > regards,
>> >> > 
>> >> > GPG key 1024D/4434BAB3 2008-08-24
>> >> > gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
>> >> > gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
>> >> > --
>> >> > For information about J forums see http://www.jsoftware.com/forums.htm
>> >> --
>> >> For information about J forums see http://www.jsoftware.com/forums.htm
>> >
>> > --
>> > regards,
>> > 
>> > GPG key 1024D/4434BAB3 2008-08-24
>> > gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
>> > gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
>> >
>> > --
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> regards,
> 
> GPG key 1024D/4434BAB3 2008-08-24
> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] zlib huffman coding

2014-09-18 Thread Raul Miller
I've modified your code to show timings:

f1=: 4 : 0
 a=. ".y
 'en de'=. x
 t=.6!:2 'assert a -: zlib_decode_so`zlib_decode_j@.de b=.
zlib_encode_so`zlib_encode_j@.en a'
 smoutput 'time: ',(10{.":t),' data: ', (20{.y),'size: ',(10":#b),'
ratio: ', ":(#b)%(#a)
)

f2=: 4 : 0
 'en de'=. x
 t=.6!:2 'assert a -: zlib_decode_so`zlib_decode_j@.de b=.
zlib_encode_so`zlib_encode_j@.en a=. fread jpath
''~user/Public/arc/zlib/test/'',y'
 smoutput 'time: ',(10{.":t),' data: ', (20{.y),'size: ',(10":#b),'
ratio: ', ":(#b)%(#a)
)

f3=: 4 : 0
 'en de'=. x
 t=.6!:2 'assert a -: zlib_decode_so`zlib_decode_j@.de b=. 1
zlib_encode_so`zlib_encode_j@.en a=. fread jpath
''~addons/data/ddsqlite/lib/'', y=. ''sqlite3.dll'''
 smoutput 'time: ',(10{.":t),' data: ', (20{.y),'size: ',(10":#b),'
ratio: ', ":(#b)%(#a)
 t=.6!:2 'assert a -: zlib_decode_so`zlib_decode_j@.de b=. 1
zlib_encode_so`zlib_encode_j@.en a=. fread jpath
''~addons/math/lapack/'', y=. ''jlapack.dll'''
 smoutput 'time: ',(10{.":t),' data: ', (20{.y),'size: ',(10":#b),'
ratio: ', ":(#b)%(#a)
)

It looks like J is about 15000 times slower than the compiled code,
and can compress some binary about twice as well, but no significant
improvement on compression ratio for text. I expect that that matches
what you are seeing?

This looks like an interesting set of potential tradeoffs.

Thanks,

-- 
Raul

On Thu, Sep 18, 2014 at 1:21 PM, Raul Miller  wrote:
> That's working.
>
> Or I think it is - I'm waiting for the script to finish, as I type this.
>
> This will obviously take some time.
>
> Thanks,
>
> --
> Raul
>
> On Thu, Sep 18, 2014 at 12:53 PM, bill lam  wrote:
>> Yes it needs to require arc/zlib. Those text files not attached,
>> also you need to change them , eg
>>
>>> zlib_encode_so`zlib_encode_j@.en a=.fread jpath'~Public/arc/zlib/test/',y
>> to
>>> zlib_encode_so`zlib_encode_j@.en a=.fread jpath'~temp/',y
>>
>> and put those file under your ~temp
>>
>> I attached the other text files for completeness. Please report
>> if they are not attached and I'll send them off-list. Thanks.
>>
>> Also in f4, change the ~Addons to ~addons and check if you got
>> those file, or try any other binary files you like. file size of
>> 1MB should be more than enough because the J script zlib is
>> quite slow.
>>
>> Чт, 18 сен 2014, Raul Miller написал(а):
>>> I see the attachment test script.
>>>
>>> I added require'arc/zlib' to the top, and then ran it, and got an
>>> error which probably means I need to do something different. But I am
>>> not sure what.
>>>
>>> Here's how it looks:
>>>
>>>   13!:1''
>>> |domain error
>>> *cd[:0]
>>> |zcompress2[0]
>>> |   0=zcompress2 buf;len;y;(#y);x
>>> |zlib_encode_so[0]
>>> |   a-:zlib_decode_so`zlib_decode_j@.de b=.
>>> zlib_encode_so`zlib_encode_j@.en a=.fread
>>> jpath'~Public/arc/zlib/test/',y
>>> |f2[:1]
>>> |   0 0 f2'algorithm.txt'
>>> |test[11]
>>> |   test''
>>> |[-100] c:\users\user\j64-803-user\temp\1.ijs
>>> |   0!:0 y[4!:55<'y'
>>> |   fn fl
>>> |   0 load y
>>> |   load'c:/users/user/j64-803-user/temp/1.ijs'
>>>
>>> Thanks,
>>>
>>> --
>>> Raul
>>>
>>>
>>> On Thu, Sep 18, 2014 at 11:42 AM, bill lam  wrote:
>>> > IMO the huffman coding part is relatively easily and performance
>>> > is acceptable, it looks like linear in time.
>>> >
>>> > the LZ77 is still very slow compared with zlib.so thus there
>>> > should be room for improvement. Test caes are in public repos
>>> > but not jal addons, I include here for your reference. Thanks.
>>> >
>>> > You may need ot modify some file path, you can replace the 4 or
>>> > 5 text files with any other text files you like, so they are not
>>> > attached.
>>> >
>>> > please let me know if the attachment test script is missing.
>>> >
>>> > After we are happy with zlib, we might try jpeg which is also a
>>> > minefi

Re: [Jprogramming] zlib huffman coding

2014-09-18 Thread Raul Miller
Oops, no. I messed up that summary.

J is within a factor of 10 on various text examples in time, and
really close in space.

On binary data, it slows down tremendously AND has worse compression
ratio. It's the compiled code that compresses binary well.

So that makes me want to understand what the compiled code is doing
differently. It probably needs some study.

Thanks,

-- 
Raul

On Thu, Sep 18, 2014 at 1:48 PM, Raul Miller  wrote:
> I've modified your code to show timings:
>
> f1=: 4 : 0
>  a=. ".y
>  'en de'=. x
>  t=.6!:2 'assert a -: zlib_decode_so`zlib_decode_j@.de b=.
> zlib_encode_so`zlib_encode_j@.en a'
>  smoutput 'time: ',(10{.":t),' data: ', (20{.y),'size: ',(10":#b),'
> ratio: ', ":(#b)%(#a)
> )
>
> f2=: 4 : 0
>  'en de'=. x
>  t=.6!:2 'assert a -: zlib_decode_so`zlib_decode_j@.de b=.
> zlib_encode_so`zlib_encode_j@.en a=. fread jpath
> ''~user/Public/arc/zlib/test/'',y'
>  smoutput 'time: ',(10{.":t),' data: ', (20{.y),'size: ',(10":#b),'
> ratio: ', ":(#b)%(#a)
> )
>
> f3=: 4 : 0
>  'en de'=. x
>  t=.6!:2 'assert a -: zlib_decode_so`zlib_decode_j@.de b=. 1
> zlib_encode_so`zlib_encode_j@.en a=. fread jpath
> ''~addons/data/ddsqlite/lib/'', y=. ''sqlite3.dll'''
>  smoutput 'time: ',(10{.":t),' data: ', (20{.y),'size: ',(10":#b),'
> ratio: ', ":(#b)%(#a)
>  t=.6!:2 'assert a -: zlib_decode_so`zlib_decode_j@.de b=. 1
> zlib_encode_so`zlib_encode_j@.en a=. fread jpath
> ''~addons/math/lapack/'', y=. ''jlapack.dll'''
>  smoutput 'time: ',(10{.":t),' data: ', (20{.y),'size: ',(10":#b),'
> ratio: ', ":(#b)%(#a)
> )
>
> It looks like J is about 15000 times slower than the compiled code,
> and can compress some binary about twice as well, but no significant
> improvement on compression ratio for text. I expect that that matches
> what you are seeing?
>
> This looks like an interesting set of potential tradeoffs.
>
> Thanks,
>
> --
> Raul
>
> On Thu, Sep 18, 2014 at 1:21 PM, Raul Miller  wrote:
>> That's working.
>>
>> Or I think it is - I'm waiting for the script to finish, as I type this.
>>
>> This will obviously take some time.
>>
>> Thanks,
>>
>> --
>> Raul
>>
>> On Thu, Sep 18, 2014 at 12:53 PM, bill lam  wrote:
>>> Yes it needs to require arc/zlib. Those text files not attached,
>>> also you need to change them , eg
>>>
>>>> zlib_encode_so`zlib_encode_j@.en a=.fread jpath'~Public/arc/zlib/test/',y
>>> to
>>>> zlib_encode_so`zlib_encode_j@.en a=.fread jpath'~temp/',y
>>>
>>> and put those file under your ~temp
>>>
>>> I attached the other text files for completeness. Please report
>>> if they are not attached and I'll send them off-list. Thanks.
>>>
>>> Also in f4, change the ~Addons to ~addons and check if you got
>>> those file, or try any other binary files you like. file size of
>>> 1MB should be more than enough because the J script zlib is
>>> quite slow.
>>>
>>> Чт, 18 сен 2014, Raul Miller написал(а):
>>>> I see the attachment test script.
>>>>
>>>> I added require'arc/zlib' to the top, and then ran it, and got an
>>>> error which probably means I need to do something different. But I am
>>>> not sure what.
>>>>
>>>> Here's how it looks:
>>>>
>>>>   13!:1''
>>>> |domain error
>>>> *cd[:0]
>>>> |zcompress2[0]
>>>> |   0=zcompress2 buf;len;y;(#y);x
>>>> |zlib_encode_so[0]
>>>> |   a-:zlib_decode_so`zlib_decode_j@.de b=.
>>>> zlib_encode_so`zlib_encode_j@.en a=.fread
>>>> jpath'~Public/arc/zlib/test/',y
>>>> |f2[:1]
>>>> |   0 0 f2'algorithm.txt'
>>>> |test[11]
>>>> |   test''
>>>> |[-100] c:\users\user\j64-803-user\temp\1.ijs
>>>> |   0!:0 y[4!:55<'y'
>>>> |   fn fl
>>>> |   0 load y
>>>> |   load'c:/users/user/j64-803-user/temp/1.ijs'
>>>>
>>>> Thanks,
>>>>
>>>> --
>>>> Raul
>>>>
>>>&g

Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2 2

2014-09-20 Thread Raul Miller
Not being a child, I originally stopped reading at
   todayno 2014 9 2014

because that sentence did not make sense to me. And once that happens,
code ceases to be interesting for me.

I also must admit to being baffled by the later requirements.

That said, age=: - would work for your stated problem and for some
people's birthdays (including mine). Actually, without some way of
checking the results, I doubt many children could distinguish between
that solution and a correct solution.

Anyways, I'm going to confess puzzlement at your approach.

Thanks,

-- 
Raul



On Sat, Sep 20, 2014 at 11:54 AM, Linda Alvord  wrote:
> We are talking children here.
>
> Onyadot. emiTetaDot, ffiDst, onyadot, emiTetaDot, emitetad,  sepyt and
> eriuqer  are all denied!
>
> How about using +, -, *, ?, %: and that sort of thing.
>
> I must admit you did get  the right answer!
>
> You can also get a second chance.
>
> Cheers,  Linda
>
>
>
> -Original Message-
> From: programming-boun...@forums.jsoftware.com
> [mailto:programming-boun...@fhorums.jsoftware.com] On Behalf Of Joe Bogner
> Sent: Saturday, September 20, 2014 9:10 AM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2 2
>
> solution...
>
>
>
>
>
>
> 1
> 2
> 3
> 4
> 5
>
>
> lightly obfuscated for someone who doesn't want the solution
>
>
> solution1=: 0 : 0
>
> )2 2 2002 onyadot emiTetaDot( ffiDst )02 9 4102 onyadot emiTetaDot(
>
> 'emitetad/sepyt' eriuqer
>
> )
>
>
>
> to run:
>
>
> 0!:1 |. solution1
>
>
>
> solution2 =: 0 : 0
>
> )2 2 2002( ffiDst )02 9 4102(
>
> 'emitetad/sepyt' eriuqer
>
> )
>
>
> 0!:1 |. solution2
>
>
>
> note: both take advantage of a addon. solution1 uses todayno just because
> it was stated in the problem but solution2 is what I'd really use
>
>
>
> On Sat, Sep 20, 2014 at 4:54 AM, Linda Alvord 
> wrote:
>
>> Using the verb  todayno  which provides the number of days since the
>> beginning of 1800,  write what you need to find the age today of a
>> groundhog
>> born on 2002 2 2.
>>
>>
>>
>>todayno 2014 9 2014
>>
>> 80418
>>
>>
>>
>>2014 9 20 age 2002 2 2
>>
>> 12 7 18
>>
>>
>>
>> His age is 12 years, 7 months and 18 days.  Use simple J.  Check that your
>> solution provides a correct answer for you birthday.
>>
>>
>>
>> Have a pleasant weekend.
>>
>>
>>
>> Linda
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2 2

2014-09-20 Thread Raul Miller
Question: How many days long is a month?

Answer: Wrong.

-- 
Raul


On Sat, Sep 20, 2014 at 1:42 PM, Linda Alvord  wrote:
> Not fair!  I want you to hand craft yhour own solution with existing verbs
> using symbols not letter names you find here and there.
>
> It must be possible if there are already solutions.  Who knows if they are
> in the most recent and beautiful J?  Give it a try.  (It's probably better
> if you don't look at those "prepared foods".
>
> Linda
>
> -Original Message-
> From: programming-boun...@forums.jsoftware.com
> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Joe Bogner
> Sent: Saturday, September 20, 2014 12:36 PM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2 2
>
> Hi Linda
>
> The solution is quite simple and uses one built verb from an addon. I
> posted it with the solution masked so others can try it on their own
> without accidentally seeing mine
>
> The actual solution is the result of this:
>
> |. solution2
> On Sep 20, 2014 11:54 AM, "Linda Alvord"  wrote:
>
>> We are talking children here.
>>
>> Onyadot. emiTetaDot, ffiDst, onyadot, emiTetaDot, emitetad,  sepyt and
>> eriuqer  are all denied!
>>
>> How about using +, -, *, ?, %: and that sort of thing.
>>
>> I must admit you did get  the right answer!
>>
>> You can also get a second chance.
>>
>> Cheers,  Linda
>>
>>
>>
>> -Original Message-
>> From: programming-boun...@forums.jsoftware.com
>> [mailto:programming-boun...@fhorums.jsoftware.com] On Behalf Of Joe Bogner
>> Sent: Saturday, September 20, 2014 9:10 AM
>> To: programm...@jsoftware.com
>> Subject: Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2
> 2
>>
>> solution...
>>
>>
>>
>>
>>
>>
>> 1
>> 2
>> 3
>> 4
>> 5
>>
>>
>> lightly obfuscated for someone who doesn't want the solution
>>
>>
>> solution1=: 0 : 0
>>
>> )2 2 2002 onyadot emiTetaDot( ffiDst )02 9 4102 onyadot emiTetaDot(
>>
>> 'emitetad/sepyt' eriuqer
>>
>> )
>>
>>
>>
>> to run:
>>
>>
>> 0!:1 |. solution1
>>
>>
>>
>> solution2 =: 0 : 0
>>
>> )2 2 2002( ffiDst )02 9 4102(
>>
>> 'emitetad/sepyt' eriuqer
>>
>> )
>>
>>
>> 0!:1 |. solution2
>>
>>
>>
>> note: both take advantage of a addon. solution1 uses todayno just because
>> it was stated in the problem but solution2 is what I'd really use
>>
>>
>>
>> On Sat, Sep 20, 2014 at 4:54 AM, Linda Alvord 
>> wrote:
>>
>> > Using the verb  todayno  which provides the number of days since the
>> > beginning of 1800,  write what you need to find the age today of a
>> > groundhog
>> > born on 2002 2 2.
>> >
>> >
>> >
>> >todayno 2014 9 2014
>> >
>> > 80418
>> >
>> >
>> >
>> >2014 9 20 age 2002 2 2
>> >
>> > 12 7 18
>> >
>> >
>> >
>> > His age is 12 years, 7 months and 18 days.  Use simple J.  Check that
>> your
>> > solution provides a correct answer for you birthday.
>> >
>> >
>> >
>> > Have a pleasant weekend.
>> >
>> >
>> >
>> > Linda
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > --
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> >
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2 2

2014-09-20 Thread Raul Miller
I agree.  But if the month is February it also depends on the year. :)

So... when you say:

"His age is 12 years, 7 months and 18 days."

Which seven months did you use?

Thanks,

-- 
Raul


On Sat, Sep 20, 2014 at 1:59 PM, Linda Alvord  wrote:
> Last I heard it depended on the month.  Linda
>
> -Original Message-
> From: programming-boun...@forums.jsoftware.com
> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Raul Miller
> Sent: Saturday, September 20, 2014 1:51 PM
> To: Programming forum
> Subject: Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2 2
>
> Question: How many days long is a month?
>
> Answer: Wrong.
>
> --
> Raul
>
>
> On Sat, Sep 20, 2014 at 1:42 PM, Linda Alvord 
> wrote:
>> Not fair!  I want you to hand craft yhour own solution with existing verbs
>> using symbols not letter names you find here and there.
>>
>> It must be possible if there are already solutions.  Who knows if they are
>> in the most recent and beautiful J?  Give it a try.  (It's probably better
>> if you don't look at those "prepared foods".
>>
>> Linda
>>
>> -Original Message-
>> From: programming-boun...@forums.jsoftware.com
>> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Joe Bogner
>> Sent: Saturday, September 20, 2014 12:36 PM
>> To: programm...@jsoftware.com
>> Subject: Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2
> 2
>>
>> Hi Linda
>>
>> The solution is quite simple and uses one built verb from an addon. I
>> posted it with the solution masked so others can try it on their own
>> without accidentally seeing mine
>>
>> The actual solution is the result of this:
>>
>> |. solution2
>> On Sep 20, 2014 11:54 AM, "Linda Alvord"  wrote:
>>
>>> We are talking children here.
>>>
>>> Onyadot. emiTetaDot, ffiDst, onyadot, emiTetaDot, emitetad,  sepyt and
>>> eriuqer  are all denied!
>>>
>>> How about using +, -, *, ?, %: and that sort of thing.
>>>
>>> I must admit you did get  the right answer!
>>>
>>> You can also get a second chance.
>>>
>>> Cheers,  Linda
>>>
>>>
>>>
>>> -Original Message-
>>> From: programming-boun...@forums.jsoftware.com
>>> [mailto:programming-boun...@fhorums.jsoftware.com] On Behalf Of Joe
> Bogner
>>> Sent: Saturday, September 20, 2014 9:10 AM
>>> To: programm...@jsoftware.com
>>> Subject: Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2
>> 2
>>>
>>> solution...
>>>
>>>
>>>
>>>
>>>
>>>
>>> 1
>>> 2
>>> 3
>>> 4
>>> 5
>>>
>>>
>>> lightly obfuscated for someone who doesn't want the solution
>>>
>>>
>>> solution1=: 0 : 0
>>>
>>> )2 2 2002 onyadot emiTetaDot( ffiDst )02 9 4102 onyadot emiTetaDot(
>>>
>>> 'emitetad/sepyt' eriuqer
>>>
>>> )
>>>
>>>
>>>
>>> to run:
>>>
>>>
>>> 0!:1 |. solution1
>>>
>>>
>>>
>>> solution2 =: 0 : 0
>>>
>>> )2 2 2002( ffiDst )02 9 4102(
>>>
>>> 'emitetad/sepyt' eriuqer
>>>
>>> )
>>>
>>>
>>> 0!:1 |. solution2
>>>
>>>
>>>
>>> note: both take advantage of a addon. solution1 uses todayno just because
>>> it was stated in the problem but solution2 is what I'd really use
>>>
>>>
>>>
>>> On Sat, Sep 20, 2014 at 4:54 AM, Linda Alvord 
>>> wrote:
>>>
>>> > Using the verb  todayno  which provides the number of days since the
>>> > beginning of 1800,  write what you need to find the age today of a
>>> > groundhog
>>> > born on 2002 2 2.
>>> >
>>> >
>>> >
>>> >todayno 2014 9 2014
>>> >
>>> > 80418
>>> >
>>> >
>>> >
>>> >2014 9 20 age 2002 2 2
>>> >
>>> > 12 7 18
>>> >
>>> >
>>> >
>>> > His age is 12 years, 7 months and 18 days.  Use simple J.  Check that
>>> your
>>> > solution provides a correct answer for you birthday.
>>> >
>>> >
>>> >
>>> > Have a pleasant weekend.
>>> >
>>> >
>>> >
>>> > Linda
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > For information about J forums see http://www.jsoftware.com/forums.htm
>>> >
>>> --
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>
>>> --
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2 2

2014-09-21 Thread Raul Miller
I think if I were teaching children, I would not immerse them in the
complexity of date systems. I think instead, I would have them draw
lines and stuff.

   7=+/~i.8
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0
0 0 0 0 0 1 0 0
0 0 0 0 1 0 0 0
0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0
0 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0

That said, if think I would also claim that the age of the groundhog
should be 12 years, 6 months and 46 days. My reasoning here is that
the days from february 2002 and the days from september 2014 do not
add together to make a complete month. February is 28 days long, and
September is 30 days long.

I can't make sense of mixing days from the two months and combining
them to get a month because we do not know how long that month is. I
do not know how long Febember should be. I'd run into a similar issue
if the date range started and ended in Februrary and only one of them
was from a leap year.

In other words here's the answers I'd produce for your test cases:

   2014 9 20 age 2002 02 02 NB. Age of Groundhog
12 6 46
   2014 9 20 age 1958 1 13  NB. I am getting too old for this :-)
56 8 7
   1989 7 29 age 1958 1 13  NB. Wedding day age
31 5 47
   2014 9 20 age 1989 7 29  NB. Years, months, days married, but who's counting
25 1 21

Maybe I should also forbid combining partial months together when they
are the same length but have different month names? I'm uncertain
about that, but I also don't feel strongly enough about the issue want
to go there.

Thanks,

-- 
Raul


On Sun, Sep 21, 2014 at 3:01 AM, robert therriault
 wrote:
> Hi Linda,
>
> I may take a look at that tomorrow, but for now I cleaned up some logic that 
> was creating problems around the one month mark and changed the dcount so 
> that it was not cumulative, but also included a left argument that allows me 
> to change the current date as well.
>
> ymd=: 4 : 0 NB. elapsed time: x is today, y is birthdate
> [:  NB. Can't think of a meaningful date for default  x so trigger domain 
> error
> :
> if. x <&todayno y do. 'Wasn''t born yet!' return. end.
> 'yb mb db' =: bday =: y
> 'yt mt dt' =: today =: x
> yt=. yt- today bdYet yt,}.bday  NB. is today before or after this year's 
> birthday
> dcount=:  (<:mb)|. 31,(28 + leap yt), 31 30 31 30 31 31 30 31 30 31 NB. 
> rotate to fit birth month
> elapsed=: -/ todayno"_1 today,: yt,}.bday NB. days since previous birthday
> mr=:_1
> if. elapsed=0 do. (yt-yb),0 0 return. end.
> while. (elapsed >: 0) do. dr=:elapsed
>mr=:>:mr
>elapsed=.elapsed -{.dcount
>dcount=.}.dcount
>end.
> (yt-yb),mr, dr NB. result in yy mm dd
> )
>
> leap=: 0= 4&|
> bdYet=:(0>-/) &: todayno  NB. returns 1 if the current date is in the same 
> calendar year before the birthday
>
>
>2014 9 20 ymd 2002 02 02 NB. Age of Groundhog
> 12 7 18
>2014 9 20 ymd 1958 1 13  NB. I am getting too old for this :-)
> 56 8 7
>1989 7 29 ymd 1958 1 13  NB. Wedding day age
> 31 6 16
>2014 9 20 ymd 1989 7 29  NB. Years, months, days married, but who's 
> counting
> 25 1 22
>ymd 2002 02 02  NB. needs to be dyadic
> |domain error: ymd
> |   ymd 2002 2 2
>
> Cheers, bob
>
>
> On Sep 20, 2014, at 11:48 PM, Linda Alvord  wrote:
>
>> That's interesting.  I started chipping away at it by finding the years
>> first. From 1800 1 1 a four year block would have 1+4*365 days or an average
>> of 365.25 per year.  So That extra wouldn't happen until 4 years had passed.
>> See if you would like it better if you remove the years first.  I'll see
>> what I get if I work in your direction.
>>
>> Linda
>>
>> -Original Message-
>> From: programming-boun...@forums.jsoftware.com
>> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of robert
>> therriault
>> Sent: Sunday, September 21, 2014 1:54 AM
>> To: programm...@jsoftware.com
>> Subject: Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2 2
>>
>> Hi Linda,
>>
>> I share your dream and sometimes the statement 'I have a dream' can change
>> the world. :-)
>>
>> On to the weekend puzzle...
>>
>> The first thing I need to figure out is whether the birthday has happened
>> this year or not. If it has then I can pretty easily get the number of days
>> since the birthday using todayno, but if it hasn't then I need to find the
>> number of days since the previous year's birthday.
>>
>> 'yg mg dg' =: gbday =: 2002 2 2  NB. Groundhog's birthday
>> 'ya ma da'=:afterbday =: 2014 9 20  NB. An example of date after the
>> birthday
>> 'yb mb db'=:beforebday =: 2014 1 31  NB. An example of a date before the
>> birthday
>>
>> bdYet=:(0>-/) &: todayno  NB. returns 1 if the current date is in the same
>> calendar year before the birthday
>>   ya
>> 2014
>>   ya=. ya- afterbday bdYet ({. afterbday),}.gbday NB.use the current year
>> from example and the birthday
>>   ya
>> 2014
>>   yb
>> 2014
>>   yb=. yb- beforebday bdYet ({. beforebday),}.gbday
>>   yb
>> 2013
>>
>> Next thing would be to d

Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2 2

2014-09-23 Thread Raul Miller
Or, in J:

isleap=: 3 :'2|+/0=4 100 400|/y'

   isleap 1900 2000 2012 2100
0 1 1 0

(I am mentioning this because I think I included a buggy version of
this expression in an earlier message - I think I left out the 0=
part.)

Thanks,

-- 
Raul


On Mon, Sep 22, 2014 at 10:13 PM, Don Kelly  wrote:
> Fortunately, the use of "leap" is valid as long as one doesn't go back past
> 1901 or ahead past 2099.
>
> 1900 and 2100 aren't leap years (Fine tuning of the leap year calculation ).
>
> Don Kelly
>
>
>
>
> On 20/09/2014 10:53 PM, robert therriault wrote:
>>
>> Hi Linda,
>>
>> I share your dream and sometimes the statement 'I have a dream' can change
>> the world. :-)
>>
>> On to the weekend puzzle...
>>
>> The first thing I need to figure out is whether the birthday has happened
>> this year or not. If it has then I can pretty easily get the number of days
>> since the birthday using todayno, but if it hasn't then I need to find the
>> number of days since the previous year's birthday.
>>
>> 'yg mg dg' =: gbday =: 2002 2 2  NB. Groundhog's birthday
>> 'ya ma da'=:afterbday =: 2014 9 20  NB. An example of date after the
>> birthday
>> 'yb mb db'=:beforebday =: 2014 1 31  NB. An example of a date before
>> the birthday
>>
>> bdYet=:(0>-/) &: todayno  NB. returns 1 if the current date is in the same
>> calendar year before the birthday
>> ya
>> 2014
>> ya=. ya- afterbday bdYet ({. afterbday),}.gbday NB.use the current
>> year from example and the birthday
>> ya
>> 2014
>> yb
>> 2014
>> yb=. yb- beforebday bdYet ({. beforebday),}.gbday
>> yb
>> 2013
>>
>> Next thing would be to define a vector that gives the accumulated days in
>> the year if the year were to start on February 1st. The leap year issue
>> means that the first item in the list will be 29 if it is a leap year. since
>> I have already figured out whether I am counting from the previous year, I
>> will use the adjusted year to decide if the year that I am counting from was
>> a leap year. I will just use a simple (and incorrect) version of leap year.
>>
>> leap=: 0= 4&|
>> feb=: 28 + leap ya
>> feb
>> 28
>> [daysFebFirst=: +/\ (feb), 31 30 31 30 31 31 30 31 30 31 31
>> 28 59 89 120 150 181 212 242 273 303 334 365
>>
>> Finally, I create the results.
>>
>> [yr=:ya-yg NB. number of years
>> 12
>>
>> [elapsed=: -/ todayno"_1 afterbday,: ya,}.gbday NB. days since the
>> birthday
>> 230
>> [mr=: +/ elapsed > daysFebFirst NB. number of months
>> 7
>> [dr=: (<:mr){ elapsed - daysFebFirst
>> 18
>> yr,mr,dr
>> 12 7 18
>>
>> And for the case of a date before the birthday Jan 31st 2014 we get
>>
>> [feb=: 28 + leap yb NB. No change since 2013 is not a leap year
>> 28
>> [yr=:yb-yg NB. number of years
>> 11
>>
>> [elapsed=: -/ todayno"_1 beforebday ,: yb ,}.gbday NB. days since the
>> previous birthday
>> 363
>> [mr=: +/ elapsed > daysFebFirst NB. number of months
>> 11
>> [dr=: (<:mr){ elapsed - daysFebFirst
>> 29
>> yr,mr,dr
>> 11 11 29
>>
>> Cheers, bob
>>
>> On Sep 20, 2014, at 10:58 AM, Linda Alvord 
>> wrote:
>>
>>> The J forum is my elementary school set of sub imjects.  What you suggest
>>> is
>>> exactly what I would hope would happen in a J classroom.  All would have
>>> J.
>>> All could experiment and exchange ideas. Hopefully they would have
>>> solutions
>>> they believe were correct.  Then they could explain their thinking to the
>>> entire class and the teacher.  At this point in the process, the teacher
>>> would not be a leader but a follower.
>>>
>>> Possibly I am dreaming
>>>
>>> Linda
>>>
>>> -Original Message-
>>> From: programming-boun...@forums.jsoftware.com
>>> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of robert
>>> therriault
>>> Sent: Saturday, September 20, 2014 1:20 PM
>>> To: programm...@jsoftware.com
>>> Subject: Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2
>>> 2
>>>
>>> Hi Linda,
>>>
>>> If you are looking for a way to get learners to be interested in the
>>> problem, why not use the very model of learning that we are using here?
>>>
>>> You put a problem out to your class (forum) and see how the responses go.
>>> You as the teacher (moderator) are free to choose the rules, knowing that
>>> the students (participants) are able to put their attention elsewhere if
>>> things are not kept interesting. It is a style of learning that we use on
>>> these forums everyday and it seems to work for us.
>>>
>>> What might not work as well is going into the class and showing them how
>>> to
>>> solve the problem, as this takes away so much from the experience that we
>>> enjoy when we are learning. The challenge for the teacher is not so much
>>> coming up with a solution, as it is to make sure that they are engaging
>>> as
>>> many students as possible. This is especially true at the extremes of the
>>> class' abilities - both the really adept and those that are struggling
>>> with
>>> the concepts are where teac

Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2 2

2014-09-24 Thread Raul Miller
I would keep in mind that calendars have a political aspect, and some
political bodies will sometimes create arbitrary calendars (I remember
a 41st of September used by the U.S. Congress a few decades ago - they
had set themselves a deadline where they needed to resolve an issue
before the end of September and then decided it was more motivating
for them to modify what September meant than to modify the deadline).

Calendars might also be used in less official works of fantasy.

Anyways, if you do not like this behavior, it's easy enough to create
a validDate verb which is an identity verb which generates errors for
invalid dates. And, once created, that verb could be used with a
variety of date manipulation verbs, in addition to todayno.

Thanks,

-- 
Raul



On Wed, Sep 24, 2014 at 7:52 PM, robert therriault
 wrote:
> I certainly see your point Linda,
>
> The tests that I run my program through are an example of creating triggers 
> to will reveal when my programming has created errors. If I was designing a 
> language that could be used in as wide a variety of ways as J, I think that 
> knowing when to generate meaningful error messages would be a very 
> challenging task. I do think that in the case of 2002 3 1 that the value 
> returned is meaningful, since that day exists. The one that I would question 
> would be 2002 2 29, which is not found on the calendar but still returns a 
> value.
>
> Cheers, bob
>
> On Sep 24, 2014, at 3:42 PM, Linda Alvord  wrote:
>
>> Using J often causes error message and they are very helpful.  They cause a
>> reassessment of the statement in question. Most often it causes a quick fix
>> as you notice the problem.  Since there is reasonalble response to todayno
>> 2002 2 29
>> I believe an error message would cause me to find the problem.
>>
>> It seems incorrect to provide the value for 2002 3 1 is not helpful.
>>
>> This may just be a minority opinion.
>>
>> Linda
>>
>> -Original Message-
>> From: programming-boun...@forums.jsoftware.com
>> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of robert
>> therriault
>> Sent: Wednesday, September 24, 2014 10:49 AM
>> To: programm...@jsoftware.com
>> Subject: Re: [Jprogramming] Weekend Puzzle - Age of Groundhog born 2002 2 2
>>
>> Hi LInda,
>>
>> Seems okay to me, since
>>
>>   (2001 3 1) diff 2001 2 28 NB. non leap year
>> 1
>>   (2000 3 1) diff 2000 2 28 NB. leap year
>> 2
>>
>>   diff=: 13 :'(todayno x)-todayno y'
>>   (2005 3 1) diff 2004 2 28
>> 367
>>   (2004 3 1) diff 2003 2 28
>> 367
>>   NB. both these intervals contain 2004 2 29 because of a leap year
>>
>>   (2003 3 1) diff 2002 2 28
>> 366
>>   (2002 3 1) diff 2001 2 28
>> 366
>>
>>   NB. these intervals don't contain a leap day
>>
>> Cheers, bob
>>
>> On Sep 24, 2014, at 2:06 AM, Linda Alvord  wrote:
>>
>>> Does this seem ok to you?
>>
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Predicting the shape of the result

2014-09-25 Thread Raul Miller
It is neither.

   $1 2 +/ i. 4
2 4

Which, perhaps would explain your dilemma?

Thanks,

-- 
Raul


On Thu, Sep 25, 2014 at 2:09 AM, Chris Wright  wrote:
> thanks Robert!
>
> OK. boxes are atoms withb an empty shape.
>
> I've looked at the docs and can't see where I could read to understand why
> shape of
>
> 1 2 +/ i. 4
>
> is 2 1 and not 1 2
>
> thanks for your help!
>
> Chris
> On 25/09/2014 4:01 PM, "robert therriault"  wrote:
>
>> Hi Chris,
>>
>> Well there is information on the vocabulary page for Table
>> http://www.jsoftware.com/help/dictionary/d420.htm
>>
>> also Nuvoc has good information on this verb
>> http://www.jsoftware.com/jwiki/Vocabulary/slash#dyadic
>>
>> The actual shape of a box is empty since the box is an atom. In the case
>> of 1 2 +/ i. 4 the shape is actually 2 4 i.e. 2 rows of 4 not 2 1
>>
>>< 1 2 +/ i. 4
>> ┌───┐
>> │1 2 3 4│
>> │2 3 4 5│
>> └───┘
>>$ < 1 2 +/ i. 4
>>$ each < 1 2 +/ i. 4
>> ┌───┐
>> │2 4│
>> └───┘
>>
>> If you wanted the two rows to be in their own boxes then you could do
>>
>>;/  1 2 +/ i. 4
>> ┌───┬───┐
>> │1 2 3 4│2 3 4 5│
>> └───┴───┘
>>or
>>
>><"1 [ 1 2 +/ i. 4
>> ┌───┬───┐
>> │1 2 3 4│2 3 4 5│
>> └───┴───┘
>>
>>$ <"1 [ 1 2 +/ i. 4
>> 2
>>
>> The above shows that the shape of the two boxes is not actually 1 2
>> because each box is an atom the shape is actually just 2.
>>
>> You are correct that an understanding of rank and shape is key to getting
>> J to work for you. If you are looking for information I have always found
>> Henry Rich's J for C Programmers much more accessible than the J
>> dictionary.  Chapters 5 and 6 are really good at explaining rank and shape
>> with regard to verbs. http://www.jsoftware.com/help/jforc/contents.htm
>>
>> Also, look at Nuvoc on the wiki. This is a crowd sourced resource
>> organized by Ian Clark and Henry Rich which many have found useful.
>> http://www.jsoftware.com/jwiki/NuVoc
>>
>> Enjoy the ride as you learn J. Welcome aboard.
>>
>> Cheers, bob
>>
>>
>> On Sep 24, 2014, at 10:35 PM, Chris Wright  wrote:
>>
>> > Hi
>> >
>> > Could I work out from the docs that
>> >
>> >  < 1 2 +/ i. 4
>> >
>> > ┌───┐
>> >
>> > │1 2 3 4│
>> >
>> > │2 3 4 5│
>> >
>> > └───┘
>> >
>> > will give the above (2 1) shape result
>> >
>> >
>> > and not a (1 2) result like below?
>> >
>> >
>> > ┌───┬───┐
>> >
>> > │1 2 3 4│2 3 4 5│
>> >
>> > └───┴───┘
>> >
>> >
>> >
>> >
>> > With the (2,1) it's obvious that two 1-cells are returned,  and with
>> (1,2)
>> > it's not obvious (where is the boundary b/n them), but I wonder if I
>> could
>> > have worked out the shape of the output from the docs alone?
>> >
>> >
>> > with thanks
>> >
>> >
>> > Chris
>> > --
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Beginner question

2014-09-25 Thread Raul Miller
Note that the original dictionary calls |. "rotate"

http://www.jsoftware.com/help/dictionary/d231.htm

It's NuVoc which calls it  "rotate left"

http://www.jsoftware.com/jwiki/Vocabulary/bardot#dyadic

I imagine the motivation here is that the rank 1 right argument case
is the simplest case, and that indicating a direction can help hold
onto the meaning.

But you are correct that for ranks greater than 1 it's "up" and not
"left". Perhaps we should edit NuVoc and call it "Rotate Left (or
Up)"?  That's a bit complicated. Perhaps instead it just deserves a
note of explanation in the description (something more than the
comment at the bottom of the current entry)??

Maybe it's best to go back to the original form of the name (not
indicating direction) and instead make an argument rank note in the
description? After all, when rotating on multiple rank,s, the name
gets ... strange.

Thanks,

-- 
Raul



On Thu, Sep 25, 2014 at 1:38 AM, Chris Wright  wrote:
> Hi
>
> Real beginner here
>
> a =: 1 2 3 4
>
> |. a
>
> 4 3 2 1 NB. yep, all is well
>
>
>
>
> now:
>
> a=: 2 3 $ i.6
>
> a
>
> 0 1 2
>
> 3 4 5
>
> 1 |. a
>
> 3 4 5
>
> 0 1 2 NB. wow! looks like "rotate up", to me
>
> (intermission while I find out about rank,axis and frame!)
>
> oh ok
>
> 1 0 |. a
>
> 3 4 5
>
> 0 1 2   NB. hmm rotate 1 on the elements of first axis - so rotate
> the 1 cells that form the rows and no rotation on the elements of the
> second axis
>
>
> 0 1|. a
>
> 1 2 0
>
> 4 5 3   NB. ok - rotate 1 on elements of the second axis - so
> rotate the 0 cell elements of the 1 cells that form the rows
>
>
> 1 |. "1 a
>
> 1 2 0
>
> 4 5 3   NB - yep
>
>
> I guess my question is about the name "rotate left" - that's only the
> "visual result" if the right operand is a 1 cell - why not call it "rotate"?
>
>
> another possibility is that I still don't understand rank/axis/frame!!! :)
>
>
> cheers
>
> --
> A/Prof Chris Wright
> MBBS, FRACP, FCICM, GradDipiSc(Physics)
> Academic Coordinator, Years III - V Central MBBS
> Intensive Care Specialist
> Faculty of Medicine, Nursing and Health Sciences,
> Monash University
> Clayton VIC
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Beginner question

2014-09-25 Thread Raul Miller
I agree.

I'm removing the 1 (it's just a wiki, so I can do that).

But I think it needs further changes.

Consider 2 _3 4 |. i. 8 8 8

The whole "left" concept, I'm not sure it makes sense as part of the name.

Thanks,

-- 
Raul



On Thu, Sep 25, 2014 at 7:40 AM, Brian Schott  wrote:
> I believe there is a "typo" at the following link where the caption "Shift
> Left 1"  should be "Shift Left x" or just "Shift Left". I suspect the
> latter because that agrees more with the reference link on the main NuVoc
> page.
>
>
>  http://www.jsoftware.com/jwiki/Vocabulary/bardot#dyadic
>
>
>
>
> --
> (B=)
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Beginner question

2014-09-25 Thread Raul Miller
Rotate is like }. though in that it is not limited to the leading
dimension, and in fact can ignore the leading dimension without using the
rank conjunction. Consider, for example:

   1 _1 |. i. 4 5
 9  5  6  7  8
14 10 11 12 13
19 15 16 17 18
 4  0  1  2  3

and

   0 2 |. i. 4 4
 2  3  0  1
 6  7  4  5
10 11  8  9
14 15 12 13

See?

Thanks,

-- 
Raul


On Thu, Sep 25, 2014 at 9:00 AM, Devon McCormick  wrote:

> Perhaps the relevant thing to understand here is that rotate - like most
> (all?) J primitives - applies to the leading axis of an array by default.
>
>+/i. 2 3  NB. Reduce "2"->shape 3 result
> 3 5 7
>+/i. 2 3 4 NB. Reduce "2"->shape 3 4 result
> 12 14 16 18
> 20 22 24 26
> 28 30 32 34
>
>(|.+]) i. 2
> 1 1
>(|.+]) i. 2 3
> 3 5 7
> 3 5 7
>(|.+]) i. 2 3 4
> 12 14 16 18
> 20 22 24 26
> 28 30 32 34
>
> 12 14 16 18
> 20 22 24 26
> 28 30 32 34
>
>
> On Thu, Sep 25, 2014 at 8:45 AM, Raul Miller 
> wrote:
>
> > I agree.
> >
> > I'm removing the 1 (it's just a wiki, so I can do that).
> >
> > But I think it needs further changes.
> >
> > Consider 2 _3 4 |. i. 8 8 8
> >
> > The whole "left" concept, I'm not sure it makes sense as part of the
> name.
> >
> > Thanks,
> >
> > --
> > Raul
> >
> >
> >
> > On Thu, Sep 25, 2014 at 7:40 AM, Brian Schott 
> > wrote:
> > > I believe there is a "typo" at the following link where the caption
> > "Shift
> > > Left 1"  should be "Shift Left x" or just "Shift Left". I suspect the
> > > latter because that agrees more with the reference link on the main
> NuVoc
> > > page.
> > >
> > >
> > >  http://www.jsoftware.com/jwiki/Vocabulary/bardot#dyadic
> > >
> > >
> > >
> > >
> > > --
> > > (B=)
> > > --
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
>
>
>
> --
> Devon McCormick, CFA
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Beginner question

2014-09-25 Thread Raul Miller
I'll do that, then.

Thanks,

-- 
Raul

On Thu, Sep 25, 2014 at 10:38 AM, Michael Dykman  wrote:

> I second the suggestion that the nuvoc name be reverted to the original
> 'rotate'
> On 25 Sep 2014 09:00, "Devon McCormick"  wrote:
>
> > Perhaps the relevant thing to understand here is that rotate - like most
> > (all?) J primitives - applies to the leading axis of an array by default.
> >
> >+/i. 2 3  NB. Reduce "2"->shape 3 result
> > 3 5 7
> >+/i. 2 3 4 NB. Reduce "2"->shape 3 4 result
> > 12 14 16 18
> > 20 22 24 26
> > 28 30 32 34
> >
> >(|.+]) i. 2
> > 1 1
> >(|.+]) i. 2 3
> > 3 5 7
> > 3 5 7
> >(|.+]) i. 2 3 4
> > 12 14 16 18
> > 20 22 24 26
> > 28 30 32 34
> >
> > 12 14 16 18
> > 20 22 24 26
> > 28 30 32 34
> >
> >
> > On Thu, Sep 25, 2014 at 8:45 AM, Raul Miller 
> > wrote:
> >
> > > I agree.
> > >
> > > I'm removing the 1 (it's just a wiki, so I can do that).
> > >
> > > But I think it needs further changes.
> > >
> > > Consider 2 _3 4 |. i. 8 8 8
> > >
> > > The whole "left" concept, I'm not sure it makes sense as part of the
> > name.
> > >
> > > Thanks,
> > >
> > > --
> > > Raul
> > >
> > >
> > >
> > > On Thu, Sep 25, 2014 at 7:40 AM, Brian Schott 
> > > wrote:
> > > > I believe there is a "typo" at the following link where the caption
> > > "Shift
> > > > Left 1"  should be "Shift Left x" or just "Shift Left". I suspect the
> > > > latter because that agrees more with the reference link on the main
> > NuVoc
> > > > page.
> > > >
> > > >
> > > >  http://www.jsoftware.com/jwiki/Vocabulary/bardot#dyadic
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > (B=)
> > > >
> --
> > > > For information about J forums see
> http://www.jsoftware.com/forums.htm
> > > --
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> >
> >
> >
> > --
> > Devon McCormick, CFA
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Repeated rolling dice

2014-09-25 Thread Raul Miller
That is very close to what I came up with, for the case where we want only
a single value from our result:

   d6=:1 + ? bind 6
   repd6=: [:+/(,d6)^:(6={:)@d6

Here's a variation on Roger Hui's approach, for the case where we want N
values from our result:

d6s=: 1 + [: ? #&6
bulk=:{.#&0(],~(+/;.1~1:}:@,0~:6&|)@(],d6s@[))^:(0=6&|@{:@{.)^:_~]

Example use:
   bulk 20
5 5 5 4 3 3 2 3 3 9 1 4 16 3 3 1 3 17 3 4

This would probably be much clearer if implemented explicitly rather than
tacitly, and probably would be more efficient also. So:

bulkd6s=:3 :0
  r=. i. 0
  while. y >: #r do.
r=. r, d6s y
mask=. }: 1, 0~:6|r
r=. mask +/;.1 r
  end.
  y{.r
)

But statistically speaking, this is still not as efficient as it could be.
I think we'd do better with:

bulkd6=:3 :0
  r=. i. 0
  while. y >: #r do.
r=. r, d6s 2*y
mask=. }: 1, 0~:6|r
r=. mask +/;.1 r
  end.
  y{.r
)

Do you see why this tends to be more efficient?

Thanks,

-- 
Raul


On Thu, Sep 25, 2014 at 11:50 AM, 'Pascal Jasmin' via Programming <
programm...@jsoftware.com> wrote:

> this works
>
> (, >:@?@6:)^:((0=#) +. 6={:)^:_ i.0
>
>([: +/ (, >:@?@6:)^:((0=#) +. 6={:)^:_) i.0
> 11
>
>
>
> - Original Message -
> From: Johann Hibschman 
> To: Programming forum 
> Cc:
> Sent: Thursday, September 25, 2014 9:06 AM
> Subject: [Jprogramming] Repeated rolling dice
>
> Hi all,
>
> For fun, I've been running some statistics for a game with an unusual
> rule for rolling dice: if a 6 is rolled, roll again and add the
> result, repeating on any subsequent 6s. I wanted to implement this in
> J, collecting all the individual rolls (rather than just the sum.)
>
> It seems like there should be a more clever and elegant way to do
> this, but this is what I have:
>
> NB. Simple roll.
> roll0 =: >:@?
>
> NB. This seems to work, but it's not very clever.
> roll =: 3 : 0
>   r =. >:?y
>   if. r=y do. r=. r,(roll y) end.
>   r
> )
>
> NB. Attempt at iterating via power.  Fails because repeats
> NB. signal termination.
> roll0^:(6&=)^:(<_) 6
>
> NB. Attempt at iterating via agenda.  Not even close yet.
> NB. ]`(]+$:) @. (=&6)  NB. where to stick in the roll?
>
> This gives what I expect:
>
>roll"0 ] 10#6
> 6 1 0
> 3 0 0
> 3 0 0
> 2 0 0
> 5 0 0
> 2 0 0
> 6 6 2
> 2 0 0
> 1 0 0
> 6 3 0
>
> But is there a better way to do this? Also, are there any known issues
> with the RNG? I've not gathered enough statistics to prove it, but the
> results look clumpier (more identical values in a row) than I expect.
> Now, I know that's a common cognitive bias, so it may just be me, but
> is there a discussion of the quality of the RNG somewhere?
>
> Thanks,
> Johann
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Beginner question

2014-09-25 Thread Raul Miller
Would "Rotate Up" work for you?

Thanks,

-- 
Raul


On Thu, Sep 25, 2014 at 5:07 PM, Henry Rich  wrote:

> I'm glad to see NuVoc getting enough use to make it worth arguing over.
>
> But I know that for myself, when |. was called simply "Rotate", I had to
> check the reference every time I used it to make sure that I got the
> direction right.  Once I learned it as "rotate left", that problem went
> away.
>
> So, please bethink ye that ye may be mistaken.  Come up with a better
> mnemonic if you can - perhaps "rotate lower" or "rotate down" - but please
> not just "rotate".
>
> Henry Rich
>
> On 9/25/2014 2:19 PM, Raul Miller wrote:
>
>> I'll do that, then.
>>
>> Thanks,
>>
>>  --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] dyad i. on sparse array

2014-09-26 Thread Raul Miller
That's an interesting question.

Here's an intermediate result:

   sdata i."1(1)
1 │ 2
2 │ 1
3 │ 1
4 │ 0

For that matter:
   sdata
1 2 │ 1
2 1 │ 1
3 1 │ 1
3 2 │ 1
4 0 │ 1

In other words, since the array is sparse, the first row does not really
"exist" - it's just the default value. In other words, you'd be getting a
dense result rather than a sparse result, to have the "this value does not
show up" behavior from i. work for you here.

Sparse matrices are quirky and limited (and, perhaps, a bit "lazy")..

-- 
Raul


On Fri, Sep 26, 2014 at 8:30 AM, Ben Gorte - CITG 
wrote:

> Good afternoon,
>
> I was finding a bug in my program that finally boiled down to this:
>
>]data =: #: i.5NB. some test data
> 0 0 0
> 0 0 1
> 0 1 0
> 0 1 1
> 1 0 0
>sdata =: $.data NB. now sparse
>
>data i."1 (1)
> 3 2 1 1 0
>
>0$. sdata i."1 (1)
> 0 2 1 1 0
>
> Shouldn't these be the same?
>
> Thanks for any advice,
>
> Ben
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Repeated rolling dice

2014-09-26 Thread Raul Miller
In addition to Pascal's comments, "0 can sometimes run into an issue with
word formation rules (when the argument to the right begins with a number).

Thanks,

-- 
Raul

On Fri, Sep 26, 2014 at 12:05 PM, Johann Hibschman 
wrote:

> Thanks, that's helpful, although the tacit version of "bulk" is a bit
> too much for me to parse.
>
> I imagine factor of 2 helps because it gets you over the expected 6r5
> rolls per "game", assuming I did that recurrence right
> (e=(5r6*1)+1r6*(1+e)).
>
> I do have some lingering style questions though:
>
> 1. It looks to me like David Lambert's solution used both (&>) and
> (">) to force a verb to apply to the atoms, which I would write ("0).
> Are there any particular reasons to prefer one over the other? ("0)
> may require a ([) to avoid merging with a follow-up literal, (&>)
> seems a little like exploiting a side-effect of (>), and (">) could
> just as easily be ("+) or any other 0 0 0 verb.
>
> 2. Is there any difference between (bind) and (@:)? They look to me
> like they would be identical.
>
> Thanks,
> Johann
>
> On Thu, Sep 25, 2014 at 3:10 PM, Raul Miller 
> wrote:
> > That is very close to what I came up with, for the case where we want
> only
> > a single value from our result:
> >
> >d6=:1 + ? bind 6
> >repd6=: [:+/(,d6)^:(6={:)@d6
> >
> > Here's a variation on Roger Hui's approach, for the case where we want N
> > values from our result:
> >
> > d6s=: 1 + [: ? #&6
> > bulk=:{.#&0(],~(+/;.1~1:}:@,0~:6&|)@(],d6s@[))^:(0=6&|@{:@{.)^:_~]
> >
> > Example use:
> >bulk 20
> > 5 5 5 4 3 3 2 3 3 9 1 4 16 3 3 1 3 17 3 4
> >
> > This would probably be much clearer if implemented explicitly rather than
> > tacitly, and probably would be more efficient also. So:
> >
> > bulkd6s=:3 :0
> >   r=. i. 0
> >   while. y >: #r do.
> > r=. r, d6s y
> > mask=. }: 1, 0~:6|r
> > r=. mask +/;.1 r
> >   end.
> >   y{.r
> > )
> >
> > But statistically speaking, this is still not as efficient as it could
> be.
> > I think we'd do better with:
> >
> > bulkd6=:3 :0
> >   r=. i. 0
> >   while. y >: #r do.
> > r=. r, d6s 2*y
> > mask=. }: 1, 0~:6|r
> > r=. mask +/;.1 r
> >   end.
> >   y{.r
> > )
> >
> > Do you see why this tends to be more efficient?
> >
> > Thanks,
> >
> > --
> > Raul
> >
> >
> > On Thu, Sep 25, 2014 at 11:50 AM, 'Pascal Jasmin' via Programming <
> > programm...@jsoftware.com> wrote:
> >
> >> this works
> >>
> >> (, >:@?@6:)^:((0=#) +. 6={:)^:_ i.0
> >>
> >>([: +/ (, >:@?@6:)^:((0=#) +. 6={:)^:_) i.0
> >> 11
> >>
> >>
> >>
> >> - Original Message -
> >> From: Johann Hibschman 
> >> To: Programming forum 
> >> Cc:
> >> Sent: Thursday, September 25, 2014 9:06 AM
> >> Subject: [Jprogramming] Repeated rolling dice
> >>
> >> Hi all,
> >>
> >> For fun, I've been running some statistics for a game with an unusual
> >> rule for rolling dice: if a 6 is rolled, roll again and add the
> >> result, repeating on any subsequent 6s. I wanted to implement this in
> >> J, collecting all the individual rolls (rather than just the sum.)
> >>
> >> It seems like there should be a more clever and elegant way to do
> >> this, but this is what I have:
> >>
> >> NB. Simple roll.
> >> roll0 =: >:@?
> >>
> >> NB. This seems to work, but it's not very clever.
> >> roll =: 3 : 0
> >>   r =. >:?y
> >>   if. r=y do. r=. r,(roll y) end.
> >>   r
> >> )
> >>
> >> NB. Attempt at iterating via power.  Fails because repeats
> >> NB. signal termination.
> >> roll0^:(6&=)^:(<_) 6
> >>
> >> NB. Attempt at iterating via agenda.  Not even close yet.
> >> NB. ]`(]+$:) @. (=&6)  NB. where to stick in the roll?
> >>
> >> This gives what I expect:
> >>
> >>roll"0 ] 10#6
> >> 6 1 0
> >> 3 0 0
> >> 3 0 0
> >> 2 0 0
> >> 5 0 0
> >> 2 0 0
> >> 6 6 2
> >> 2 0 0
> >> 1 0 0
> >> 6 3 0
> >>
> >> But is there a better way to do this? Also, are there any known issues
> >> with the RNG? I've not gathered enough statistics to prove it, but the
> >> results look clumpier (more identical values in a row) than I expect.
> >> Now, I know that's a common cognitive bias, so it may just be me, but
> >> is there a discussion of the quality of the RNG somewhere?
> >>
> >> Thanks,
> >> Johann
> >> --
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> >>
> >> --
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> >>
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] JHS on a local network

2014-09-26 Thread Raul Miller
Speaking as a student, I have always been frustrated by demos which depend
on "behind the scenes setup".  I think I have had a similar issue with some
labs, but I do not remember any specific examples. The issue is that when I
take the code and start playing with it, it does not work.

So I would advise caution with hiding things too much.

Tha said, it's quite reasonable to "start in the middle" - where the
"interesting stuff happens" and then go back over the preparatory steps
later (when the student will have motivation to be interested in those
steps).

That said, you do not need to do anything fancy with a lab to refer to
external things. A single load statement can execute arbitrarily complex
code, and if you build everything in a target directory in ~addons (perhaps
~addons/labs/jhs-turtles/ or ~addons/jhs/turtle-lab/) then you can refer to
files locally and expect them to mostly work when deployed through the
addons sstem (if that is your eventul intent, once you are happy with our
presentation).

That said... looking at what you have done so far, I expect you'll have
more than enough material to fill a book, before you are done. (Though much
of it might be more infrastructure topics than "turtle" topics.)

Thanks,

-- 
Raul

On Fri, Sep 26, 2014 at 1:08 PM, Brian Schott 
wrote:

> Bob,
>
> Are you suggesting that a Lab which includes a graphic like the one in
> tgsjhs.ijs can be constructed? Are there any Labs you can suggest? I tried
> the Plot lab but the plots are embedded in the text, not in a stationary
> window/frame like in tgsjhs. Is there a Lab for vlite.ijs, for example?
>
> I had not really thought about a Lab for tgsjhs. I could use some ideas on
> that.
>
> On Fri, Sep 26, 2014 at 12:16 PM, robert therriault  >
> wrote:
>
> > Hi Brian,
> >
> > Slightly different approach, but you can do things behind the scenes by
> > using the PREPARE keyword in a lab. You still need to get the learner to
> do
> > something to have the PREPARE'd statements execute, but it becomes less
> > visible if you were already using the lab as a learning scaffold and
> > executing specific instructions is just a matter of advancing the lab.
> >
> > Cheers, bob
> >
> > --
> (B=)
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Length errors when getting multiple columns from array

2014-09-26 Thread Raul Miller
These two statements give equivalent results:

   3 4{."1&.>3
3
   >3 4
3 4
   2 *&> 3 4
6 8
   <&.>3 4
+---+---+
|+-+|+-+|
||3|||4||
|+-+|+-+|
+---+---+
   ]"(-&>)
]"0 0 0

I hope this helps.

Thanks,

-- 
Raul


On Fri, Sep 26, 2014 at 1:12 PM, Jon Hough  wrote:

> Yes. Thanks. That is what I want, exactly. I just need a little time to
> digest what you've done. I'm not sure why arr is being boxed. Presumably
> under (&.) wants a boxed argument.
> I'm also not sure why your implicit loop, 2 4{."1 , works while mine
> didn't.
> Is there somewhere in the dictionary/NuVoc that explains this?
> I am aware that f&.> is often used to unbox an argument, apply f to the
> result and then box it again. But am not sure how that applies to my
> problem.
>
>
> > Date: Fri, 26 Sep 2014 12:51:03 -0400
> > From: devon...@gmail.com
> > To: programm...@jsoftware.com
> > Subject: Re: [Jprogramming] Length errors when getting multiple columns
> from  array
> >
> > Not entirely sure what you want, but is this it?
> >
> >3 4{."1&.> > +-+---+
> > |0 1 2|0 1 2 3|
> > |6 7 8|6 7 8 9|
> > |2 3 4|2 3 4 5|
> > |8 9 0|8 9 0 1|
> > |4 5 6|4 5 6 7|
> > |0 1 2|0 1 2 3|
> > |6 7 8|6 7 8 9|
> > |2 3 4|2 3 4 5|
> > |8 9 0|8 9 0 1|
> > |4 5 6|4 5 6 7|
> > +-+---+
> >
> >
> > On Fri, Sep 26, 2014 at 12:44 PM, Jon Hough  wrote:
> >
> > > I have a 2-d array. e.g.
> > > arr =: 10 6 $ i. 10
> > > I want to get the first 3 columns from the array, e.g.  3{."1and get
> the
> > > first 4 elements, e.g. 4{."1
> > > However, combining these, as in
> > > 3 4 {."(0 1) arrgives a length error. Of course 3{. and 4{.  will give
> > > different shape results so should be boxed and then concatenated
> > > perhaps(?). I am not sure how to do this, but the end result I want
> would
> > > be something like:
> > >
> > > ┌─┐
> > >
> > > │0 1 2│
> > >
> > > │6 7 8│
> > >
> > > │2 3 4│
> > >
> > > │8 9 0│
> > >
> > > │4 5 6│
> > >
> > > │0 1 2│
> > >
> > > │6 7 8│
> > >
> > > │2 3 4│
> > >
> > > │8 9 0│
> > >
> > > │4 5 6│
> > >
> > > └─┘
> > >
> > >
> > > concatenated with
> > >
> > >
> > > ┌───┐│0 1 2 3││6 7 8 9││2 3 4 5││8 9 0 1││4 5 6 7││0 1 2 3││6 7 8
> 9││2
> > > 3 4 5││8 9 0 1││4 5 6 7│
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > └───┘
> > >
> > >
> > >
> > > --
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> >
> >
> >
> > --
> > Devon McCormick, CFA
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] XML addons for J802

2014-09-27 Thread Raul Miller
The compiled C code behind the addon is not very stable, and crashes J. The
32 bit j602 version seems to work the best. (It at least does not crash for
simple xml parsing, though it does crash when parsing something like
nif.xml.)

Thanks,

-- 
Raul


On Sat, Sep 27, 2014 at 2:56 AM, Jon Hough  wrote:

> It seems the XML addons, which are visible in the package manager for
> J602, are not available for J802.Is there a reason for this?Will copying
> the scripts to J802 addons cause issues?
> Thanks,Jon
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Length errors when getting multiple columns from array

2014-09-27 Thread Raul Miller
That's a good point.

But the addon doesn't even have a wiki page, yet.

You want me to put one together?

Thanks,

-- 
Raul

On Sat, Sep 27, 2014 at 9:11 AM, Henry Rich  wrote:

> For problems like this, the dissect addon can help you see what's
> happening.
>
> Henry Rich
>
> On 9/27/2014 12:47 AM, Raul Miller wrote:
>
>> These two statements give equivalent results:
>>
>> 3 4{."1&.>>
>> and
>>
>> ((<3),(<4)){."1&.>>
>> Here's a few exercises which might help:
>> >3
>> 3
>> >3 4
>> 3 4
>> 2 *&> 3 4
>> 6 8
>> <&.>3 4
>> +---+---+
>> |+-+|+-+|
>> ||3|||4||
>> |+-+|+-+|
>> +---+---+
>> ]"(-&>)
>> ]"0 0 0
>>
>> I hope this helps.
>>
>> Thanks,
>>
>>  --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Length errors when getting multiple columns from array

2014-09-27 Thread Raul Miller
I see the problem:

I tried to use a search engine to find the page

However, http://www.jsoftware.com/robots.txt lists jwiki which means that
search engines will no longer show new wiki content.

So that probably means someone needs to deal with
http://moinmo.in/HowTo/Tune%20Performance

Perhaps also
https://www.paypal.com/us/cgi-bin/webscr?cmd=_donate-intro-outside to cover
costs.

That's all I can think of at the moment. (Well.. no, it's not -
hypothetically speaking web traffic is subject to spikes -- the "slashdot
effect" -- and when that happens performance drops to a crawl. There are
companies like cloudflare which are set up to deal with such things, but
that costs money. Meanwhile, advertising funds a lot of web development.
But all too often, advertising is annoying and/or stupid - sometimes it
even hosts malware. So high quality sites want to minimize ad spam. So that
suggests a business model something like cloudflare but where pages host ad
content only during traffic spikes (which of course would need a
definition). But that's getting way more complicated than what we probably
want to tackle.

Thanks,

-- 
Raul


On Sat, Sep 27, 2014 at 9:37 AM, Henry Rich  wrote:

> Oh, it does:
>
> http://www.jsoftware.com/jwiki/Vocabulary/Dissect
>
> I guess it must be hard to find.  Any suggestions for improving visibility
> would be appreciated.
>
> Henry Rich
>
> On 9/27/2014 9:20 AM, Raul Miller wrote:
>
>> That's a good point.
>>
>> But the addon doesn't even have a wiki page, yet.
>>
>> You want me to put one together?
>>
>> Thanks,
>>
>>  --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] jqt (j803) edit window

2014-10-03 Thread Raul Miller
In the jqt edit window, there's a green "play button" which runs the
current script.

Unfortunately, it does this in a way which prevents 4!:4 and 4!:5 from
finding where the script is stored.

What was the motivation for implementing it this way? (Obviously this is a
problem when we want to locate content in the same directory as the loaded
script, but maybe there's some benefit that's more important?)

Thanks,

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


Re: [Jprogramming] How can I I box items in an array

2014-10-04 Thread Raul Miller
If that is what you want, here is another approach:

   ({.,({.,.{:)@}.)":@<"0 'HIJ'
┌─┐
│H│
└─┘
┌─┐┌─┐
│I││J│
└─┘└─┘

If you want extra spaces somewhere you could insert them in a variety of
ways.

Thanks,

-- 
Raul


On Sat, Oct 4, 2014 at 8:28 AM, Linda Alvord 
wrote:

> Aha! It can be done.   Thanks.
>
> Linda
>
> -Original Message-
> From: programming-boun...@forums.jsoftware.com
> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Aai
> Sent: Saturday, October 04, 2014 5:41 AM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] How can I I box items in an array
>
> Ok , in this particular case:
>
> (<<<3)&{@}.@}:@|:^:2 ": 2 2$ ]`(''"_)@.(' '&=&>)L:1 <&.> 'H IJ'
> --┐
> │H│
> L--
> --┐--┐
> │I││J│
> L--L--
>
>
>
> On 04-10-14 04:00, Linda Alvord wrote:
> > What I would like to do is box the three letters in a so the boxes do not
> > touch each other.
> >
> > ]A=:2 2$'H IJ'
> > H
> > IJ
> > ]B=:<"0 A
> > --T-┐
> > │H│ │
> > +-+-+
> > │I│J│
> > L-+--
> > ]C=:<"0 B
> > T---┐
> > │--┐│--┐│
> > ││H│││ ││
> > │L--│L--│
> > +---+---+
> > │--┐│--┐│
> > ││I│││J││
> > │L--│L--│
> > L---+
> > ]D=:(<'') (< 0 1)}C
> > T---┐
> > │--┐│   │
> > ││H││   │
> > │L--│   │
> > +---+---+
> > │--┐│--┐│
> > ││I│││J││
> > │L--│L--│
> > L---+
> > >D
> > --┐
> > │H│
> > +-+
> > │ │
> > L--
> >
> > --┐
> > │I│
> > +-+
> > │J│
> > L--
> >
> > The result should have only three boxes. It should look llike D, but
> without
> > the outer square of 4 smaller squares.  I thought it would be easy,  but:
> >
> > Linda
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> Met vriendelijke groet,
> @@i = Arie Groeneveld
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] How can I I box items in an array

2014-10-04 Thread Raul Miller
On Sat, Oct 4, 2014 at 10:56 AM, David Lambert  wrote:
> http://rosettacode.org/wiki/Maze_solving#J

That doesn't work.

   4 (display~ solve)@maze 9
|value error: maze

Can you fix it?

Thanks,

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


Re: [Jprogramming] How can I I box items in an array

2014-10-04 Thread Raul Miller
Oops, I need to define maze from the other task (referred to in the
task description). I typicall update the text of the entry to make
that sort of dependency clear when I'm writing one of those things.

That said, it still doesn't work, when I also include the definition
of maze and display from the other task, or when I only include the
definition of maze from the other task and display from this one.

   4 (display~ solve)@maze 9
|value error: path

Maybe I should look at this more closely, but for now I'll simply note
that this is confusing. (And I am also a bit uncomfortable about the
re-definition of the name 'display' in this context. That kind of
ambiguity is just asking for trouble. Perhaps 'show' instead, for the
version here? Or are they intended to be workalikes? Normally, I'd
just see what the code does but since it doesn't work I feel that
asking is appropriate.)

Thanks,

-- 
Raul


On Sat, Oct 4, 2014 at 3:16 PM, Raul Miller  wrote:
> On Sat, Oct 4, 2014 at 10:56 AM, David Lambert  wrote:
>> http://rosettacode.org/wiki/Maze_solving#J
>
> That doesn't work.
>
>4 (display~ solve)@maze 9
> |value error: maze
>
> Can you fix it?
>
> Thanks,
>
> --
> Raul
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] what is happening here?

2014-10-08 Thread Raul Miller
I paste a definition into my J session:

   appendbox=:1 :0
:
  pfx=. ,1 4{.y
  assert. pfx-:,_1 4{.y
  if. ' ' e. pfx do. '' return. end.
  prefix=. (2{.pfx),'/',pfx
  dir=: 'Reference/',prefix
  (;x,&.>LF) fileappend dir,'/data06.txt'
)

And then I inspect the name

   appendbox
1 : 0
  pfx=. ,1 4{.y
  assert. pfx-:,_1 4{.y
  if. ' ' e. pfx do. '' return. end.
  prefix=. (2{.pfx),'/',pfx
  dir=: 'Reference/',prefix
  (;x,&.>LF) fileappend dir,'/data06.txt'
)

Somehow my adverb has mutated.

What is going on here?

Thanks,

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


Re: [Jprogramming] what is happening here?

2014-10-08 Thread Raul Miller
Worse... I work around this... whatever it is.. by changing the definition:

$ ijconsole
   appendbox=:1 : 0
  y
:
  pfx=. ,1 4{.y
  assert. pfx-:,_1 4{.y
  if. ' ' e. pfx do. '' return. end.
  prefix=. (2{.pfx),'/',pfx
  dir=: 'Reference/',prefix
  (;x,&.>LF) fileappend dir,'/data06.txt'
)
   1 'a' appendbox 2
|value error: y
|   y
   9!:14''
j701/2011-01-10/11:25


How can I be getting a value error on y? Why is the monadic definition
being used in the dyadic case? How can I get anything done when things are
this crazy?

Can anyone else reproduce this?

Thanks,

-- 
Raul






On Wed, Oct 8, 2014 at 11:22 AM, Raul Miller  wrote:

> I paste a definition into my J session:
>
>appendbox=:1 :0
> :
>   pfx=. ,1 4{.y
>   assert. pfx-:,_1 4{.y
>   if. ' ' e. pfx do. '' return. end.
>   prefix=. (2{.pfx),'/',pfx
>   dir=: 'Reference/',prefix
>   (;x,&.>LF) fileappend dir,'/data06.txt'
> )
>
> And then I inspect the name
>
>appendbox
> 1 : 0
>   pfx=. ,1 4{.y
>   assert. pfx-:,_1 4{.y
>   if. ' ' e. pfx do. '' return. end.
>   prefix=. (2{.pfx),'/',pfx
>   dir=: 'Reference/',prefix
>   (;x,&.>LF) fileappend dir,'/data06.txt'
> )
>
> Somehow my adverb has mutated.
>
> What is going on here?
>
> Thanks,
>
> --
> Raul
>
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] what is happening here?

2014-10-08 Thread Raul Miller
Oh, duh -- copy and paste coding, and I stripped out the 'm'.

I guess I'd like a default "braindead" mode for when I am recovering from
being ill (like today) or very tired.

(This would issue domain errors at define time if x and y are being
promoted to u/v significance.)

I'm not sure how hard that would be to implement, however.

Thanks,

-- 
Raul



On Wed, Oct 8, 2014 at 11:48 AM, 'Pascal Jasmin' via Programming <
programm...@jsoftware.com> wrote:

> you have reference x and y without u or m.  There is a global setting (6!
> or 9! something) to turn this off I think.  I don't see why you are using
> an adverb here.
>
> on another note:
>
>bind
> 2 : 'x@(y"_)'
>
> is there any case where the definition 2 : 'u@(v"_)' would fail or
> produce a different result?
>
>
> - Original Message -
> From: Raul Miller 
> To: Programming forum 
> Cc:
> Sent: Wednesday, October 8, 2014 11:29 AM
> Subject: Re: [Jprogramming] what is happening here?
>
> Worse... I work around this... whatever it is.. by changing the definition:
>
> $ ijconsole
>appendbox=:1 : 0
>   y
> :
>   pfx=. ,1 4{.y
>   assert. pfx-:,_1 4{.y
>   if. ' ' e. pfx do. '' return. end.
>   prefix=. (2{.pfx),'/',pfx
>   dir=: 'Reference/',prefix
>   (;x,&.>LF) fileappend dir,'/data06.txt'
> )
>1 'a' appendbox 2
> |value error: y
> |   y
>9!:14''
> j701/2011-01-10/11:25
>
>
> How can I be getting a value error on y? Why is the monadic definition
> being used in the dyadic case? How can I get anything done when things are
> this crazy?
>
> Can anyone else reproduce this?
>
> Thanks,
>
> --
> Raul
>
>
>
>
>
>
>
>
>
> On Wed, Oct 8, 2014 at 11:22 AM, Raul Miller 
> wrote:
>
> > I paste a definition into my J session:
> >
> >appendbox=:1 :0
> > :
> >   pfx=. ,1 4{.y
> >   assert. pfx-:,_1 4{.y
> >   if. ' ' e. pfx do. '' return. end.
> >   prefix=. (2{.pfx),'/',pfx
> >   dir=: 'Reference/',prefix
> >   (;x,&.>LF) fileappend dir,'/data06.txt'
> > )
> >
> > And then I inspect the name
> >
> >appendbox
> > 1 : 0
> >   pfx=. ,1 4{.y
> >   assert. pfx-:,_1 4{.y
> >   if. ' ' e. pfx do. '' return. end.
> >   prefix=. (2{.pfx),'/',pfx
> >   dir=: 'Reference/',prefix
> >   (;x,&.>LF) fileappend dir,'/data06.txt'
> > )
> >
> > Somehow my adverb has mutated.
> >
> > What is going on here?
> >
> > Thanks,
> >
> > --
> > Raul
> >
> >
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] what is happening here?

2014-10-08 Thread Raul Miller
I think you want http://www.jsoftware.com/help/dictionary/d310n.htm

Especially points 4 and 5.

But I actually haven't found anything that suggests that x and y are
analogs for u and v when u and v are not used. I think that might be pure
backwards compatibility (which suggests it should be treated in am manner
analogous to 9!:48 and 9!:49).

Thanks,

-- 
Raul


On Wed, Oct 8, 2014 at 2:39 PM, Joe Bogner  wrote:

> Speaking of x and y, u and m... Is there a cheat sheet for them and the
> rules?
>
> A rule being " you have referenced x and y without u or m.  "
>
> Some places I've looked:
> 1.  http://www.jsoftware.com/help/dictionary/dictc.htm (very light)
> 2.  http://www.jsoftware.com/jwiki/Vocabulary/Modifiers
> 3.
>
> http://www.jsoftware.com/help/jforc/loopless_code_ii_adverbs__an.htm#_Toc191734359
> 4. http://www.jsoftware.com/help/learning/13.htm
> 5.
>
> http://www.jsoftware.com/jwiki/MarkusSchmidtGroettrup?action=AttachFile&do=view&target=j_schnell_referenz_20070616.pdf
> (page six)
>
> #2 and #4 are probably the best I've found so far
>
> I was working this morning and couldn't remember the rules so I started to
> write each permutation as
>
> 1 (2 : 'smoutput x;y') 2
> 1 (2 : 'smoutput u;v;y') 2 'a'
> 10 (2 : 'u v 2') +
> 10 (2 : 'u v y') + 3
>
> ...
>
>
>
> On Wed, Oct 8, 2014 at 2:19 PM, Raul Miller  wrote:
>
> > Oh, duh -- copy and paste coding, and I stripped out the 'm'.
> >
> > I guess I'd like a default "braindead" mode for when I am recovering from
> > being ill (like today) or very tired.
> >
> > (This would issue domain errors at define time if x and y are being
> > promoted to u/v significance.)
> >
> > I'm not sure how hard that would be to implement, however.
> >
> > Thanks,
> >
> > --
> > Raul
> >
> >
> >
> > On Wed, Oct 8, 2014 at 11:48 AM, 'Pascal Jasmin' via Programming <
> > programm...@jsoftware.com> wrote:
> >
> > > you have reference x and y without u or m.  There is a global setting
> (6!
> > > or 9! something) to turn this off I think.  I don't see why you are
> using
> > > an adverb here.
> > >
> > > on another note:
> > >
> > >bind
> > > 2 : 'x@(y"_)'
> > >
> > > is there any case where the definition 2 : 'u@(v"_)' would fail or
> > > produce a different result?
> > >
> > >
> > > - Original Message -
> > > From: Raul Miller 
> > > To: Programming forum 
> > > Cc:
> > > Sent: Wednesday, October 8, 2014 11:29 AM
> > > Subject: Re: [Jprogramming] what is happening here?
> > >
> > > Worse... I work around this... whatever it is.. by changing the
> > definition:
> > >
> > > $ ijconsole
> > >appendbox=:1 : 0
> > >   y
> > > :
> > >   pfx=. ,1 4{.y
> > >   assert. pfx-:,_1 4{.y
> > >   if. ' ' e. pfx do. '' return. end.
> > >   prefix=. (2{.pfx),'/',pfx
> > >   dir=: 'Reference/',prefix
> > >   (;x,&.>LF) fileappend dir,'/data06.txt'
> > > )
> > >1 'a' appendbox 2
> > > |value error: y
> > > |   y
> > >9!:14''
> > > j701/2011-01-10/11:25
> > >
> > >
> > > How can I be getting a value error on y? Why is the monadic definition
> > > being used in the dyadic case? How can I get anything done when things
> > are
> > > this crazy?
> > >
> > > Can anyone else reproduce this?
> > >
> > > Thanks,
> > >
> > > --
> > > Raul
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > On Wed, Oct 8, 2014 at 11:22 AM, Raul Miller 
> > > wrote:
> > >
> > > > I paste a definition into my J session:
> > > >
> > > >appendbox=:1 :0
> > > > :
> > > >   pfx=. ,1 4{.y
> > > >   assert. pfx-:,_1 4{.y
> > > >   if. ' ' e. pfx do. '' return. end.
> > > >   prefix=. (2{.pfx),'/',pfx
> > > >   dir=: 'Reference/',prefix
> > > >   (;x,&.>LF) fileappend dir,'/data06.txt'
> > > > )
> > > >
> > > > And then I inspect the name
> > > >
> > > >appendbox
> > > > 1 : 0
> > > >   pfx=. ,1 4{.y
> > > >   assert. pfx-:,_1 4{.y
> > > >   if. ' ' e. pfx do. '' return. end.
> > > >   prefix=. (2{.pfx),'/',pfx
> > > >   dir=: 'Reference/',prefix
> > > >   (;x,&.>LF) fileappend dir,'/data06.txt'
> > > > )
> > > >
> > > > Somehow my adverb has mutated.
> > > >
> > > > What is going on here?
> > > >
> > > > Thanks,
> > > >
> > > > --
> > > > Raul
> > > >
> > > >
> > > --
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> > > --
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] what is happening here?

2014-10-08 Thread Raul Miller
My preference for feature removal starts with making the feature optional.

Once you can turn it off, it's relatively easy to test for what that breaks.

Once most of the breakage is fixed, you can release with it turned off by
default.

(The migration from x./y. to x/y for verb parameters skipped directly to
"turned off by default" which I think was a mistake. But that's old news
now.)

That said - do you happen to know where the dictionary documents that 2
:'u,v' and 2 :'x,y' behave the same?

Thanks,

-- 
Raul

On Wed, Oct 8, 2014 at 7:47 PM, Henry Rich  wrote:

> It's just backwards compatibility, but a lot of the standard scripts rely
> on it, and someone would have to do a bit of work to allow the feature to
> be removed.
>
> Henry Rich
>
> On 10/8/2014 6:20 PM, Raul Miller wrote:
>
>> I think you want http://www.jsoftware.com/help/dictionary/d310n.htm
>>
>> Especially points 4 and 5.
>>
>> But I actually haven't found anything that suggests that x and y are
>> analogs for u and v when u and v are not used. I think that might be pure
>> backwards compatibility (which suggests it should be treated in am manner
>> analogous to 9!:48 and 9!:49).
>>
>> Thanks,
>>
>>  --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] A minor amusement

2014-10-08 Thread Raul Miller
You know what this expression will give, yes?

   3 :'2 assert. 1' 0

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


Re: [Jprogramming] A minor amusement

2014-10-09 Thread Raul Miller
To clear up a point raised in an off-list discussion, consider this:

  3 :'r=.2 assert. 5=r=.r+3 assert. 10=r=.r+5' 0

According to http://www.jsoftware.com/help/dictionary/ctrl.htm

Control words are used in Explicit Definition (:) and are punctuation that
determine the sequence of execution.

So J sentences in an explicit definition are separated by control words and
the control words determin the order of execution of those sentences.

In the case of assert, that order of execution is left to right. You can
put an assert on a line to have it verify the result computed on its left
hand side.

Thanks,

-- 
Raul

On Wed, Oct 8, 2014 at 11:22 PM, Raul Miller  wrote:

> You know what this expression will give, yes?
>
>3 :'2 assert. 1' 0
>
> --
> Raul
>
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Splitting vector

2014-10-09 Thread Raul Miller
I'd probably go with

   i. 8
0 1 2 3 4 5 6 7
   |:_2]\ i.8
0 2 4 6
1 3 5 7

But I see that Bob Therriault has already proposed this mechanism.

You could also do something using selection masks, but I see that Pascal
Jasmin has already proposed something along that line.

So here's another approach:
   (({~ |:@i.) >.@-:@#,2:) i.8
0 2 4 6
1 3 5 7

But that's probably a bit silly.

Thanks,

-- 
Raul


On Thu, Oct 9, 2014 at 6:00 PM, Andrey Paramonov  wrote:

> Hello everyone,
> What is the best way in J to split a vector into two vectors by even and
> odd indices? For example, for this input
>
> 0 1 2 3 4 5 6 7
> I want the following output
>
> 0 2 4 6
>
> 1 3 5 7
>
>
>
> Thank you.
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Project Euler 85, Python and J

2014-10-11 Thread Raul Miller
Yes:

This mechanism, and the insight behind it, is the heart of the
multi-dimensional array mechanism.

As a simple example, if you have a 10x10x10 array, and you want the value
at index 6,7,3 that value is at index 673 of the ravel of that array.

It's about which representation is most convenient for the operation you
are performing.

Thanks,

-- 
Raul

On Sat, Oct 11, 2014 at 1:43 AM, Jon Hough  wrote:

> Also, regarding Ben Gorte's
>
> Idot =: $ #: I.@:,
>
> This is an equivalent of I. for higher dimensions.
>
> I'm having trouble understanding how this works.
>
> Here is my understanding.
>
> 1. ravel the matrix and index elements (I.@:,)
> 2. Next is a fork of $ #: I.@:,
>
>Right "prong" is the aforementioned element indices.
>
>Left "prong" is the shape of the original array/matrix.
>
>middle "prong" is  the antibase of the right prong w.r.t. the left.
>
> This seems to work for matrices of any size or dimension.
>
> Is this the standard way to index multidimensional arrays?
>
>
>
> > From: jgho...@outlook.com
> > To: programm...@jsoftware.com
> > Date: Sat, 11 Oct 2014 06:33:45 +0100
> > Subject: Re: [Jprogramming] Project Euler 85, Python and J
> >
> > Using (2 ! >:) is clearly better than doing my double for-loop. I'm
> embarrassed I missed that.
> >
> > The real meat of my confusion with multidimensional arrays is in not
> just finding the indices but doing something with the elements at the
> indices.
> >
> > e.g. For a single dimension array, there could be a function to fund the
> primes less than 100.
> >
> >
> > primelist =: (I.@:(1&=)@:(1&p:)) { ]
> >
> >
> > and primelist >: i. 100
> >
> >
> > should spit out
> >
> >
> > 2 3 5 ...  ...97
> >
> >
> > But what if instead of having >: i. 100
> >
> > I had ( for some reason )
> >
> >  arr =: 10 10 $ >: i. 100
> >
> >
> > So I have a 10 by 10 matrix of all positive ints up to 100.
> >
> >
> > primelist clearly will not work on arr. But if I want to return the list
> of primes, as a single dimensional list I'm not sure how to do that.
> >
> >
> > Or, for example, if I want to change the elements of arr to 1 if and
> only if the sum of the (i, j) indices are prime (just a random example).
> >
> >
> > In procedural python this could be quickly done with a double for-loop
> and a prime test. In J this type of problem still escapes me.
> >
> >
> >
> > > Date: Fri, 10 Oct 2014 19:35:26 -0400
> > > From: devon...@gmail.com
> > > To: programm...@jsoftware.com
> > > Subject: Re: [Jprogramming] Project Euler 85, Python and J
> > >
> > >countRects=: */@(2 ! >:) NB. How many pairs each of
> vertical
> > > * horizontal lines
> > >getSizes=: ,@(>:/~) # [: ,/ ,"0/~NB. All pairs of i. y
> > >idxClosest=: 4 : '(i. <./)@(x |@:- ])y'"(0 2)   NB. Index of mat y
> to
> > > value x
> > >({~ *2e6*&idxClosest@:(countRects"1)) getSizes >: i.200NB.
> Closest
> > > to 2e6
> > > 77 36
> > >({~ *1e6*&idxClosest@:(countRects"1)) getSizes >: i.200NB.
> Closest
> > > to 1e6
> > > 63 31
> > >countRects"1 ] 63 31,:77 36 NB. How close is each?
> > > 36 198
> > >
> > >
> > > On Fri, Oct 10, 2014 at 1:14 PM, Linda Alvord  >
> > > wrote:
> > >
> > > > What is the correct answerfor this problem?
> > > >
> > > > Linda
> > > >
> > > > -Original Message-
> > > > From: programming-boun...@forums.jsoftware.com
> > > > [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of
> Stefano
> > > > Lanzavecchia
> > > > Sent: Friday, October 10, 2014 11:47 AM
> > > > To: programm...@jsoftware.com
> > > > Subject: Re: [Jprogramming] Project Euler 85, Python and J
> > > >
> > > > Actuary the use of ravel and antibase is common practice to solve
> > > > certain problems in APL and isn't considered cheating. So I wouldn't
> > > > say it's "not nice" but I would definitely go for antibase instead of
> > > > a combination of floored-divide and modulus. As a bonus, a solution
> > > > based on antibase would scale to problems of any rank and not just 2d
> > > > matrices.
> > > >
> > > > Have fun!
> > > > --
> > > > Stefano
> > > >
> > > > > On 10/ott/2014, at 17:35, Sebastiano Tronto <
> sebastiano.tro...@gmail.com
> > > > >
> > > > wrote:
> > > > >
> > > > > Hi,
> > > > > A dirty trick to get the job done would be to ravel the matrix ( ,
> ),
> > > > solve
> > > > > the 1d version of the problem and then get the "true" indexes with
> > > > > something like (<.@%&200 , 200&|).
> > > > > For example, if you needed to just find the max:
> > > > > (<.@%&200 , 200&|) (i. >./) , m
> > > > > where m is your matrix.
> > > > >
> > > > > I know this isn't a nice way to solve the problem, but it should
> work.
> > > > >
> > > > > Sebastiano
> > > > >
> > > > > 2014-10-07 6:37 GMT+02:00 Jon Hough :
> > > > >
> > > > >> Project Euler 85: https://projecteuler.net/problem=85
> > > > >> This problem is not really conceptually hard, but I am struggling
> with a
> > > > J
> > > > >> solution.I have solved it in Python:
> > > > >> ===

Re: [Jprogramming] Project Euler 85, Python and J

2014-10-11 Thread Raul Miller
I understand that boxed index lists can be used to index multi-dimensioned
arrays. And that can be a convenient abstraction.

However, I have been dealing with very large datasets recently, and boxed
data on the critical path, at least for some operations, becomes
prohibitively slow.

When I can use regular numeric structures to replace irregular boxed
structures, the overall speedup from the representation change usually more
than makes up for the cost of changing representation.

Thanks,

-- 
Raul

On Sat, Oct 11, 2014 at 11:48 AM, Devon McCormick 
wrote:

> I think what you may be missing is that boxed items can be used to index an
> array of dimensions higher than 1:
>
>]rr=. 10 10?@$1000
> 590 147 158 729 522 732 355   5 955 673
> 858 350 740 105 669 546 334 840 546 184
> 629 608 375 697 224 240 921 182 477 509
> 463 692 151 192 639 115 543 589 636 769
> 240 916 823 902 529 591 757 343 755 622
> 589 665 484 430 849 430 460 987 769 628
> 731 581 107  42  23 145 195 820 223 487
> 725 362 263 376 945 883 760 897 675 188
>  89 884 484 790 793 178 131 324 291 199
> 527  52 725 187 867 297 411 495 985 478
>]whprm=. rr e. p: i.>./,rr  NB. Which are prime?
> 0 0 0 0 0 0 0 1 0 1
> 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 1
> 1 0 1 0 0 0 0 0 0 1
> 0 0 1 0 0 0 1 0 0 0
> 0 0 0 0 0 0 0 0 1 0
> 0 0 1 0 1 0 0 0 1 1
> 0 0 1 0 0 1 0 0 0 0
> 1 0 0 0 0 0 1 0 0 1
> 0 0 0 0 0 0 0 0 0 0
>
> Say we want to replace all primes by 1:
>
>whprm+rr*-.whprm   NB. Arithmetical way
> 590 147 158 729 522 732 355   1 955   1
> 858 350 740 105 669 546 334 840 546 184
> 629 608 375 697 224 240 921 182 477   1
>   1 692   1 192 639 115 543 589 636   1
> 240 916   1 902 529 591   1 343 755 622
> 589 665 484 430 849 430 460 987   1 628
> 731 581   1  42   1 145 195 820   1   1
> 725 362   1 376 945   1 760 897 675 188
>   1 884 484 790 793 178   1 324 291   1
> 527  52 725 187 867 297 411 495 985 478
>
> or, since
>($ #: I.@:,) whprm
> 0 7
> 0 9
> 2 9
> 3 0
> 3 2
> 3 9
> 4 2
> 4 6
> 5 8
> 6 2
> 6 4
> 6 8
> 6 9
> 7 2
> 7 5
> 8 0
> 8 6
> 8 9
>(1) (<"1 ($ #: I.@:,) whprm) } rr  NB. Using indexes
> 590 147 158 729 522 732 355   1 955   1
> 858 350 740 105 669 546 334 840 546 184
> 629 608 375 697 224 240 921 182 477   1
>   1 692   1 192 639 115 543 589 636   1
> 240 916   1 902 529 591   1 343 755 622
> 589 665 484 430 849 430 460 987   1 628
> 731 581   1  42   1 145 195 820   1   1
> 725 362   1 376 945   1 760 897 675 188
>   1 884 484 790 793 178   1 324 291   1
> 527  52 725 187 867 297 411 495 985 478
>
>
>
> On Sat, Oct 11, 2014 at 4:02 AM, Raul Miller 
> wrote:
>
> > Yes:
> >
> > This mechanism, and the insight behind it, is the heart of the
> > multi-dimensional array mechanism.
> >
> > As a simple example, if you have a 10x10x10 array, and you want the value
> > at index 6,7,3 that value is at index 673 of the ravel of that array.
> >
> > It's about which representation is most convenient for the operation you
> > are performing.
> >
> > Thanks,
> >
> > --
> > Raul
> >
> > On Sat, Oct 11, 2014 at 1:43 AM, Jon Hough  wrote:
> >
> > > Also, regarding Ben Gorte's
> > >
> > > Idot =: $ #: I.@:,
> > >
> > > This is an equivalent of I. for higher dimensions.
> > >
> > > I'm having trouble understanding how this works.
> > >
> > > Here is my understanding.
> > >
> > > 1. ravel the matrix and index elements (I.@:,)
> > > 2. Next is a fork of $ #: I.@:,
> > >
> > >Right "prong" is the aforementioned element indices.
> > >
> > >Left "prong" is the shape of the original array/matrix.
> > >
> > >middle "prong" is  the antibase of the right prong w.r.t. the left.
> > >
> > > This seems to work for matrices of any size or dimension.
> > >
> > > Is this the standard way to index multidimensional arrays?
> > >
> > >
> > >
> > > > From: jgho...@outlook.com
> > > > To: programm...@jsoftware.com
> > > > Date: Sat, 11 Oct 2014 06:33:45 +0100
> > > > Subject: Re: [Jprogramming] Project Euler 85, Python and J
> > > >
> > > > Using (2 ! >:) is clearly better than doing my double for-loop. I'm
> > > embarrassed I missed that.
> > > >
> > > > The real meat of my confusion with multidimensional arrays is in not
> > > just finding the indices but doing something with the elemen

Re: [Jprogramming] Project Euler 85, Python and J

2014-10-13 Thread Raul Miller
Looking over this primelist issue...

One of the first things I would probably do, would be to review the
dictionary entry for p:

http://www.jsoftware.com/help/dictionary/dpco.htm

And notice:
   1 p: 1 2 3 4 5
0 1 1 0 1

So primelist might be written as:
   primelist=: 1&p: # ]

Testing:
   primelist 1 2 3 4 5
2 3 5

Meanwhile, if you want the primes from a 10 by 10 array, first translate
the array into a list (using comma):
   arr=: 1+i.10 10
   primelist,arr
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Or, for "change numbers in arr to 1 if the sum of the indices is prime, I
might do something like this:

   arr^0 p:+/&i./$arr
 1  2  1  1  5  1  7  1  9  10
11  1  1 14  1 16  1 18 19  20
 1  1 23  1 25  1 27 28 29   1
 1 32  1 34  1 36 37 38  1  40
41  1 43  1 45 46 47  1 49   1
 1 52  1 54 55 56  1 58  1  60
61  1 63 64 65  1 67  1 69  70
 1 72 73 74  1 76  1 78 79  80
81 82 83  1 85  1 87 88 89   1
91 92  1 94  1 96 97 98  1 100

Explanation:

I can change the elements of arr to 1 by raising them to the zero-th power
(changing to an arbitrary value would require slightly more work).

I can get zeros corresponding to primes using 0 p: (from reading that
dictionary entry).

The expression +/&i./$arr works out like this:
   +/&i./$arrNB. the concise expression
   +/&i./10 10   NB. definition of $
   10 +/&i. 10   NB. definition of /
   (i.10) +/ (i.10)  NB. definition of & using +/ and i.
0  1  2  3  4  5  6  7  8  9
1  2  3  4  5  6  7  8  9 10
2  3  4  5  6  7  8  9 10 11
3  4  5  6  7  8  9 10 11 12
4  5  6  7  8  9 10 11 12 13
5  6  7  8  9 10 11 12 13 14
6  7  8  9 10 11 12 13 14 15
7  8  9 10 11 12 13 14 15 16
8  9 10 11 12 13 14 15 16 17
9 10 11 12 13 14 15 16 17 18

Mostly, I guess, there are a few dozen vocabulary words here to master.
Once you've gotten comfortable with them, you should have a rough idea of
which ones might be relevant to a topic.

Also, there's the matter of getting used to working on arrays "as a whole"
and/or thinking about treating each item independently when possible.

That's all I can think of that might be relevant for this kind of thing.

Thanks,

-- 
Raul


On Sat, Oct 11, 2014 at 1:33 AM, Jon Hough  wrote:

> Using (2 ! >:) is clearly better than doing my double for-loop. I'm
> embarrassed I missed that.
>
> The real meat of my confusion with multidimensional arrays is in not just
> finding the indices but doing something with the elements at the indices.
>
> e.g. For a single dimension array, there could be a function to fund the
> primes less than 100.
>
>
> primelist =: (I.@:(1&=)@:(1&p:)) { ]
>
>
> and primelist >: i. 100
>
>
> should spit out
>
>
> 2 3 5 ...  ...97
>
>
> But what if instead of having >: i. 100
>
> I had ( for some reason )
>
>  arr =: 10 10 $ >: i. 100
>
>
> So I have a 10 by 10 matrix of all positive ints up to 100.
>
>
> primelist clearly will not work on arr. But if I want to return the list
> of primes, as a single dimensional list I'm not sure how to do that.
>
>
> Or, for example, if I want to change the elements of arr to 1 if and only
> if the sum of the (i, j) indices are prime (just a random example).
>
>
> In procedural python this could be quickly done with a double for-loop and
> a prime test. In J this type of problem still escapes me.
>
>
>
> > Date: Fri, 10 Oct 2014 19:35:26 -0400
> > From: devon...@gmail.com
> > To: programm...@jsoftware.com
> > Subject: Re: [Jprogramming] Project Euler 85, Python and J
> >
> >countRects=: */@(2 ! >:) NB. How many pairs each of
> vertical
> > * horizontal lines
> >getSizes=: ,@(>:/~) # [: ,/ ,"0/~NB. All pairs of i. y
> >idxClosest=: 4 : '(i. <./)@(x |@:- ])y'"(0 2)   NB. Index of mat y to
> > value x
> >({~ *2e6*&idxClosest@:(countRects"1)) getSizes >: i.200NB.
> Closest
> > to 2e6
> > 77 36
> >({~ *1e6*&idxClosest@:(countRects"1)) getSizes >: i.200NB.
> Closest
> > to 1e6
> > 63 31
> >countRects"1 ] 63 31,:77 36 NB. How close is each?
> > 36 198
> >
> >
> > On Fri, Oct 10, 2014 at 1:14 PM, Linda Alvord 
> > wrote:
> >
> > > What is the correct answerfor this problem?
> > >
> > > Linda
> > >
> > > -Original Message-
> > > From: programming-boun...@forums.jsoftware.com
> > > [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Stefano
> > > Lanzavecchia
> > > Sent: Friday, October 10, 2014 11:47 AM
> > > To: programm...@jsoftware.com
> > > Subject: Re: [Jprogramming] Project Euler 85, Python and J
> > >
> > > Actuary the use of ravel and antibase is common practice to solve
> > > certain problems in APL and isn't considered cheating. So I wouldn't
> > > say it's "not nice" but I would definitely go for antibase instead of
> > > a combination of floored-divide and modulus. As a bonus, a solution
> > > based on antibase would scale to problems of any rank and not just 2d
> > > matrices.
> > >
> > > Have fun!
> > > --
> > > Stefano
> > >
> > > > On 10/ott/2014, at 17:35, Sebasti

[Jprogramming] if.

2014-10-13 Thread Raul Miller
   verb def '0 if. 1 do. 2 else. 3 end.' 4
2
   verb def '0 if. 1 do. 2 else. 3 end. 4' 5
4

That's another example of "Control words are used in Explicit
Definition (:) and are punctuation that determine the sequence of
execution."

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


Re: [Jprogramming] if.

2014-10-13 Thread Raul Miller
I guess I do not understand your question.

Can you restate it?

Thanks,

-- 
Raul

On Mon, Oct 13, 2014 at 10:35 PM, Henry Rich  wrote:
> Is that what that means?  Are you sure?
>
> There's no doubt about it in NuVoc:
>
> http://www.jsoftware.com/jwiki/Vocabulary/Words#Control_Words
>
> Some inflected names, such as if., do., and end., are control words. They
> are used to control program flow. These words are treated as sentences in
> themselves. They break up the executable line into a number of separate
> sentences -- the control words, and the phrases between the control words.
>
>
> Henry Rich
>
>
> On 10/13/2014 10:18 PM, Raul Miller wrote:
>>
>> verb def '0 if. 1 do. 2 else. 3 end.' 4
>> 2
>> verb def '0 if. 1 do. 2 else. 3 end. 4' 5
>> 4
>>
>> That's another example of "Control words are used in Explicit
>> Definition (:) and are punctuation that determine the sequence of
>> execution."
>>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] J code for integer partitions & scale-weight balancing?

2014-10-13 Thread Raul Miller
I decided to investigate the inefficiency of the Skiena algorithm:

   timespacex 'Knuth 10'
0.000739266 11520
   timespacex 'Skiena~ 10'
0.000520212 13568
   timespacex 'Knuth 20'
0.011861 202112
   timespacex 'Skiena~ 20'
0.00808606 294656
   timespacex 'Knuth 30'
0.0345268 3.15174e6
   timespacex 'Skiena~ 30'
0.0318853 4.40192e6
   timespacex 'Knuth 40'
0.233694 2.51721e7
   timespacex 'Skiena~ 40'
0.281741 3.51424e7
   $Knuth 40
37338 40
   $Knuth 30
5604 30

We start seeing the inefficiency for result sizes on the order of 10k
rows.  (I'm not refining that result because the inefficiency is too
trivial to be significant at this stage.)

   timespacex 'Skiena~ 50'
2.08078 2.74745e8
   timespacex 'Knuth 50'
1.3436 2.01333e8
   timespacex 'Skiena~ 60'
12.6631 1.14088e9
   timespacex 'Knuth 60'
6.25185 8.05313e8
   $Knuth 50
204226 50
   $Knuth 60
966467 60

The inefficiency becomes significant (factor of 2) for result sizes on
the order of half a million rows.

Of course in practice you'd probably want to compute this once and the
use the stored result.

-- 
Raul


On Mon, Oct 13, 2014 at 11:26 PM, Devon McCormick  wrote:
> http://www.jsoftware.com/jwiki/DevonMcCormick/HAP_AIP
> is an essay by Howard Peele on "All Integer Partitions".
>
> On Mon, Oct 13, 2014 at 9:31 PM, Jon Hough  wrote:
>
>> If you search jsoftware for
>> Partitions r.e. boss
>>
>> There is a dictionary page about power u^:v
>>
>> At the bottom of the page is a verb for finding Partitions, by r.e. boss.
>> It may be helpful.
>>
>> --- Original Message ---
>>
>> From: "Devon McCormick" 
>> Sent: October 14, 2014 9:07 AM
>> To: "J-programming forum" 
>> Subject: Re: [Jprogramming] J code for integer partitions & scale-weight
>>   balancing?
>>
>> Have you spoken w/Howard Peele about the latter one?
>>
>> On Mon, Oct 13, 2014 at 6:19 PM, Murray Eisenberg <
>> murrayeisenb...@gmail.com
>> > wrote:
>>
>> > Has anybody translated into J the solutions to two problems posed in the
>> > most recent Vector (Vol 26, Nos. 2 & 3) and solved there in APL, namely:
>> >
>> > (1) Determining the masses of a complex system of scales (levers) and
>> > weights -- Brian Becker's article "One reason that APL is so cool".
>> >
>> > (2) Finding all partitions of a given integer n into exactly k distinct
>> > positive integers -- Don Baronet's article, "A tool of thought".
>> >
>> > If so, would you be willing to share?
>> >
>> > I ask because I'm a bit rusty with J, and have no access to any modern
>> APL
>> > interpreter for OS X my Mac.
>> >
>> > ---
>> > Murray Eisenbergmurrayeisenb...@gmail.com
>> > 503 King Farm Blvd #101 Home (240)-246-7240
>> > Rockville, MD 20850-6667Mobile (413)-427-5334
>> >
>> >
>> >
>> >
>> >
>> > --
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> >
>>
>>
>>
>> --
>> Devon McCormick, CFA
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
>
>
> --
> Devon McCormick, CFA
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] if.

2014-10-13 Thread Raul Miller
I have no objection to the use of NuVoc.

But I'd not want to abandon the dictionary, either.

Thanks,

-- 
Raul


On Mon, Oct 13, 2014 at 11:34 PM, Henry Rich  wrote:
> The question was rhetorical.
>
> The Dictionary line
>
>   Control words are used in Explicit Definition (:) and are
>   punctuation that determine the sequence of execution
>
> is true, but not fully informative.  The NuVoc version explains more
> completely - and if it's not complete enough, you can emend it.
>
> I'm suggesting that if we all use NuVoc as the main reference, we'll be
> better off, in the long run.
>
> Henry Rich
>
>
> On 10/13/2014 11:08 PM, Raul Miller wrote:
>>
>> I guess I do not understand your question.
>>
>> Can you restate it?
>>
>> Thanks,
>>
>> -- Raul On Mon, Oct 13, 2014 at 10:35 PM, Henry Rich
>>  wrote:
>>>
>>> >Is that what that means?  Are you sure?
>>> >
>>> >There's no doubt about it in NuVoc:
>>> >
>>> >http://www.jsoftware.com/jwiki/Vocabulary/Words#Control_Words
>>> >
>>> >Some inflected names, such as if., do., and end., are control words.
>>> > They
>>> >are used to control program flow. These words are treated as sentences
>>> > in
>>> >themselves. They break up the executable line into a number of separate
>>> >sentences -- the control words, and the phrases between the control
>>> > words.
>>> >
>>> >
>>> >Henry Rich
>>> >
>>> >
>>> >On 10/13/2014 10:18 PM, Raul Miller wrote:
>>>>
>>>> >>
>>>> >> verb def '0 if. 1 do. 2 else. 3 end.' 4
>>>> >>2
>>>> >> verb def '0 if. 1 do. 2 else. 3 end. 4' 5
>>>> >>4
>>>> >>
>>>> >>That's another example of "Control words are used in Explicit
>>>> >>Definition (:) and are punctuation that determine the sequence of
>>>> >>execution."
>>>> >>
>>>
>>> >--
>>> >For information about J forums seehttp://www.jsoftware.com/forums.htm
>>
>> --
>> For information about J forums seehttp://www.jsoftware.com/forums.htm
>>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Project Euler 85, Python and J

2014-10-14 Thread Raul Miller
Your approach looks very sensible. But I am curious about this result,
which is not what I expected:
   bestmn 1e3
7 8 8 7

If I change the second to last line in bestmnv to read
  i =. (i. <./) d

I get
   bestmn 1e3
7 8

Are there cases where this would be a problem?

Thanks,

-- 
Raul

On Tue, Oct 14, 2014 at 5:39 AM, Mike Day  wrote:
> OK - I've re-engineered a solution method which deals with
> required numbers several orders of magnitude higher than
> 2e6.  I expect my original approach was the whole array
> approach as recently discussed,  but I can't find it anywhere
> in my files.
>
> Apologies for any silly line-throws.
>
> The maths shows that the number of embedded rectangles
> in a grid of size (m,n) is tri(m)*tri(n) where tri is a triangular
> number, ie one in the series 0 1 3 6 10 15 
> tri(n) is n(n+1)%2
>
> It's easy to find which (m,m) most closely approximates the
> required number, req, by solving the quadratic
> m(m+1) = 2 sqrt(req)
>
> Let mmax = ceil(m)
>
> Also, for a given m,  we can solve the quadratic
> n(n+1) = 4 req % m(m+1)
>
> In general, we get two integers bounding the non-
> integer solution, one of which will generally give
> a number of rectangles closer to the required
> value.
>
> Find the best pair (m,n) over m in [1,mmax]
>
> NB. Number of rectangles in mxn is tri(m)*tri(n)
>
> nrec =: *&(-:*>:)
>
>
> NB. best (m,n) over given vector m=y for target x
>
> bestmnv =: 3 : 0
>
> :
>
> req =. x [ m =. y
>
> NB. solve n(n+1)m(m+1) = 4*req
>
> NB. ie n^2 + n + 1-4.req/m(m+1) = 0
>
> NB. Get upper & lower integer bounds to each (usually) real solution
>
> n =. (<.,>.) _0.5 + %:_0.75 + 4*req% (*>:) m
>
> d =. (m=.m,m) (req |@-nrec) n NB. absolute errors
>
> i =. ((I.@(=(<./))@,)) d NB. index of least error
>
> m (,&(i&{) )n
>
> )
>
>
> NB. Find best m,n for required number of rectangles y
>
> bestmn =: 3 : 0
>
> req =. y
>
> NB. get maximum m, when n=m
>
> mmax=. >. _0.5 + %:_0.75 + 2*%:req NB. round up solution when m=n
>
> req bestmnv >:i.mmax
>
> )
>
>
> Here are a couple of targets suggested in the Project Euler discussion
> on this topic. The whole array approach discussed in the J forum would
>
> find them challenging.
>
>
>  timer'bestmn x:<.9.87654321e19'
>
> +-++
>
> |5.628|20214 983262|
>
> +-++
>
> timer'bestmn 123456789123456789x'
>
> ++--+
>
> |0.830002|7198 97621|
>
> ++--+
>
>
> Thanks,
>
> Mike
>
>
>
>
> On 12/10/2014 11:30, Linda Alvord wrote:
>>
>> At the moment, I'm rooting for 54 by 54 as the answer!
>>
>> ff=: 13 :'(>:i.x)  */>:i.y'
>> f=:  13 :'*/~ >:i.y'
>> (7 ff 7)-:f 7
>>   good=: 13 :'}:1,x>+/\,y'
>> sum=: 13 :'+/(x good y)#, y'
>>
>> 400 < 400 sum 5 ff 5
>> 400 < 400 sum 6 ff 6
>> 400 < 400 sum 7 ff 7
>> 400 sum f 6
>> 400 sum f 7
>> 400 sum f 8
>> 6 ff 6
>> 400 sum 6 ff 6
>>
>> 2e6 < 2e6 sum 52 ff 52
>> 2e6 < 2e6 sum 53 ff 53
>> 2e6 < 2e6 sum 54 ff 54
>> 2e6 sum f 53
>> 2e6 sum f 54
>> 2e6 sum f 55
>> 2e6 sum 54 ff 54
>>
>> This stays in 2 dimensions.
>>
>> Linda
>>
>>
>> -Original Message-
>> From: programming-boun...@forums.jsoftware.com
>> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Raul Miller
>> Sent: Saturday, October 11, 2014 6:10 PM
>> To: Programming forum
>> Subject: Re: [Jprogramming] Project Euler 85, Python and J
>>
>> I understand that boxed index lists can be used to index multi-dimensioned
>> arrays. And that can be a convenient abstraction.
>>
>> However, I have been dealing with very large datasets recently, and boxed
>> data on the critical path, at least for some operations, becomes
>> prohibitively slow.
>>
>> When I can use regular numeric structures to replace irregular boxed
>> structures, the overall speedup from the representation change usually
>> more
>> than makes up for the cost of changing representation.
>>
>> Thanks,
>>
>
>
>
> ---
> This email is free from viruses and malware because avast! Antivirus
> protection is active.
> http://www.avast.com
>
>
>
> -
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2014.0.4765 / Virus Database: 4040/8386 - Release Date: 10/14/14
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Insert a 2 dimensional array to a n dimensional array

2014-10-21 Thread Raul Miller
   new=:3 3$1
   old=:4 4$0

   new (($new) <@#: i.$new)} old
1 1 1 0
1 1 1 0
1 1 1 0
0 0 0 0

   new (($new) <@(0 1&+)@#: i.$new)} old
0 1 1 1
0 1 1 1
0 1 1 1
0 0 0 0

You can replace the 0 1 with any valid coordinate for the upper left corner.

You can either make this an explicit definition, or you can build up
an expression using a gerund to where } places the data.

If you want to go the gerund route, see also:

http://www.jsoftware.com/help/dictionary/d530n.htm
http://www.jsoftware.com/jwiki/Vocabulary/curlyrt#dyadic

... and then (a) build up an expression that works and then (b) find
good ways to name significant parts of that expression.

But for amend it's often simpler to use explicit definitions - also
there's a mild space efficiency hack in the language which favors
explicit contexts for amend. (Search for the word "special" on that
jwiki vocabulary page for a brief mention of this issue).

Is that enough to get you started?

Thanks,

-- 
Raul


On Tue, Oct 21, 2014 at 10:04 AM, Sebastian  wrote:
> Hello,
>
> I have a question similar to the question I had a few weeks before. The
> question was how replace single values from a matrix
> (http://jsoftware.com/pipermail/programming/2014-September/039225.html). Now
> I would like to replace a matrix with at least 2 dimensions with values from
> a 2 dimensional array.
>
> The new values should replace the old values from the matrix, like this:
>
> new data:
> 1 1 1
> 1 1 1
> 1 1 1
>
> old data:
> 0 0 0 0
> 0 0 0 0
> 0 0 0 0
> 0 0 0 0
>
> result:
>
> 1 1 1 0
> 1 1 1 0
> 1 1 1 0
> 0 0 0 0
>
> The insert position to the matrix should be parameterisable.
>
> Best regards
> Sebastian
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Insert a 2 dimensional array to a n dimensional array

2014-10-21 Thread Raul Miller
P.S. if you want to avoid boxing (for speed):

   ($old)$(,new) (($old) #. ($new) #: i.$,new)} ,old
1 1 1 0
1 1 1 0
1 1 1 0
0 0 0 0
   ($old)$(,new) (($old) #. 0 1+"1 ($new) #: i.$,new)} ,old
0 1 1 1
0 1 1 1
0 1 1 1
0 0 0 0

Thanks,

-- 
Raul

On Tue, Oct 21, 2014 at 1:24 PM, Raul Miller  wrote:
>new=:3 3$1
>old=:4 4$0
>
>new (($new) <@#: i.$new)} old
> 1 1 1 0
> 1 1 1 0
> 1 1 1 0
> 0 0 0 0
>
>new (($new) <@(0 1&+)@#: i.$new)} old
> 0 1 1 1
> 0 1 1 1
> 0 1 1 1
> 0 0 0 0
>
> You can replace the 0 1 with any valid coordinate for the upper left corner.
>
> You can either make this an explicit definition, or you can build up
> an expression using a gerund to where } places the data.
>
> If you want to go the gerund route, see also:
>
> http://www.jsoftware.com/help/dictionary/d530n.htm
> http://www.jsoftware.com/jwiki/Vocabulary/curlyrt#dyadic
>
> ... and then (a) build up an expression that works and then (b) find
> good ways to name significant parts of that expression.
>
> But for amend it's often simpler to use explicit definitions - also
> there's a mild space efficiency hack in the language which favors
> explicit contexts for amend. (Search for the word "special" on that
> jwiki vocabulary page for a brief mention of this issue).
>
> Is that enough to get you started?
>
> Thanks,
>
> --
> Raul
>
>
> On Tue, Oct 21, 2014 at 10:04 AM, Sebastian  wrote:
>> Hello,
>>
>> I have a question similar to the question I had a few weeks before. The
>> question was how replace single values from a matrix
>> (http://jsoftware.com/pipermail/programming/2014-September/039225.html). Now
>> I would like to replace a matrix with at least 2 dimensions with values from
>> a 2 dimensional array.
>>
>> The new values should replace the old values from the matrix, like this:
>>
>> new data:
>> 1 1 1
>> 1 1 1
>> 1 1 1
>>
>> old data:
>> 0 0 0 0
>> 0 0 0 0
>> 0 0 0 0
>> 0 0 0 0
>>
>> result:
>>
>> 1 1 1 0
>> 1 1 1 0
>> 1 1 1 0
>> 0 0 0 0
>>
>> The insert position to the matrix should be parameterisable.
>>
>> Best regards
>> Sebastian
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


  1   2   3   4   5   6   7   8   9   10   >