Re: [Jprogramming] Ragged Array Shapes are Trees
in terms of copying one node to another, ((1 ; 0)&{:: <@[ each amendT 0 ]) 0 ;<(< i.5);i.4 ┌───┬─┐ │┌─┐│┌───┬───┐│ ││0 1 2 3 4│││┌─┐│0 1 2 3││ │└─┘│││0 1 2 3 4││ ││ │ ││└─┘│ ││ │ │└───┴───┘│ └───┴─┘ to delete the original node (move) {: each amendT 1 ((1 ; 0)&{:: <@[ each amendT 0 ]) (0 ;<(< i.5);i.4) ┌───┬─┐ │┌─┐│┌───┐│ ││0 1 2 3 4│││0 1 2 3││ │└─┘│└───┘│ └───┴─┘ When I said tree processing is ok, I was thinking more of user trees rather than "system trees" where the relationship among nodes is also user defined. I should also point out that it is only ok after definining my own functions to deal with trees. and I will repeat that I agree that }:: (with compatible indexing to {::) would be a big improvement, though the above uses a fairly simple workaround. - Original Message - From: Dan Bron To: programm...@jsoftware.com Cc: Sent: Monday, September 8, 2014 2:30 PM Subject: Re: [Jprogramming] Ragged Array Shapes are Trees 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 -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Ragged Array Shapes are Trees
I think that is awesome, Thomas. For those who didn't load the code, its much easier to use than it looks as everything is a verb, and the whole thing is like a mini stack language, and each operation produces intuitive and visible results. - Original Message - From: Thomas Costigliola To: J Programming Forum Cc: Sent: Monday, September 8, 2014 4:04 PM Subject: Re: [Jprogramming] Ragged Array Shapes are Trees Array representations and "pointer" representations of trees both have their uses. In the end it depends on what problem you are trying to solve. As Devon demonstrated, for his purpose, array representation was not a hindrance at all. But, as Dan mentions, trees are also used to implement abstract data structures with certain run-time properties where finding the children of a node or inserting / moving sub-trees in less than constant time is not acceptable. J already can do the "pointer" representation with boxed arrays but as stated by others previously, there are insufficient primitives for working with them conveniently without additional overhead. I have played around with code similar to Pascal's for working with trees. I felt, however, this type of stuff has limited usefulness in production code without help from the interpreter to optimize it. It's the same idea as a "zipper" data structure in other languages. Here is a bare bones implementation with lots of room for more bells and whistles if desired. x=. @ [ y=. @ ] focus=. (3&{::) y addrs=. (2&{::) y crumbs=. (1&{::) y stack=. (0&{::) y zip=. '';'';'';< unzip=. focus @: (zout ^: (#@crumbs)) zin=. (stack) ; (crumbs , <@focus) ; (addrs , 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 -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Ragged Array Shapes are Trees
L. might be a candidate. (depth) # of leaves (boxes) might be the most popular ([: +/ 1: S:0) When a tree holds nested records (say customers invoices products bought), then the # of records could be defined as just # . You might want to know number of invoices, but can't naively use L: because a customer might also have nested phone numbers or other data. The point of this blabbering is that sometimes # is domain specific. - Original Message - From: Dan Bron To: programm...@jsoftware.com Cc: Sent: Tuesday, September 9, 2014 9:24 AM Subject: Re: [Jprogramming] Ragged Array Shapes are Trees Here's a question to chew on. What's the # of a tree? - Original Message --- Subject: Re: [Jprogramming] Ragged Array Shapes are Trees From: "Michal D." Date: Mon, 8 Sep 2014 23:04:34 -0700 To: programm...@jsoftware.com Thanks for the links, they make for interesting reading. I agree that the elegance of the solution is the hard part. Nevertheless there have been previous attempts at ragged arrays that we can potentially learn from: nested arrays in APL and K to some degree. I was hoping to find out more about the various approaches that have come up in the past. It's interesting to me that the restriction that one places on what type of ragged arrays are allowed is also exactly the type of raggedness required for representing a shape of such an array (this is an observation not a fact): 1) Arrays are rectangular : a rectangular rank-1 array is enough to describe the shape. 2) Arrays are rectangular except for the last dimension : the shape can be represented by a rank-2 array with singleton entries for the leading axes and a rank-1 array describing the size of each last dimension. 3) Arrays are arbitrarily ragged : the shape can be represented as a tree (ie. a boxed or arbitrarily ragged array). Cheers, Mike On Mon, Sep 8, 2014 at 10:54 AM, Dan Bron wrote: > I expand on this in a little more detail in the Wiki page I linked to, but > (in my view), there are two aspects to address w.r.t. trees in J; > efficiency is one of the two questions, but the less interesting one > ("efficiency is a SMOP" [1]). > > The other, more interesting question, is "convenience". Is it convenient to > create, address, manipulate and process trees -- qua trees, not in the > guise of orthotopic arrays -- in J? And I mean "convenient" in the way > creating, addressing, manipulating and processing orthotopic arrays is > "convenient" in J. Are trees convenient in J? Short answer: no. > > Solution? Language (re-)design. > > Anyone want to volunteer for the task of making tree programming as > seamless, elegant, beautiful, and (to steal a phrase from Alan Perlis) > lyrical in J as array programming? > > -Dan > > [1] SMOP: >http://www.catb.org/jargon/html/S/SMOP.html > (tongue-in-cheek, though I do believe "redesign the language" makes > "improve the performance of trees" seem easy by comparison.) > > > > - Original Message --- > > Subject: Re: [Jprogramming] Ragged Array Shapes are Trees >From: Raul Miller >Date: Mon, 8 Sep 2014 12:00:05 -0400 > To: Programming forum > > Note that J already supports trees. > > After all, that's what directories are, and J supports directories > (albeit using foreigns). > > As for the efficiency of trees, well... you can see for yourself, from > first hand experience. Operating systems, after all, have many many > years of effort which have gone into making them "more efficient". > > Thanks, > > -- > Raul > > > On Mon, Sep 8, 2014 at 11:56 AM, Dan Bron wrote: > > I do think trees, if we did it right (that is, treated as first class > > citizens in their own right, as opposed to a subtype or a different > > perspective on "arrays"), would be a powerful extension to the language. > > That would take some serious thought, though: for one thing, trees, by > > their nature, encourage "thinking little" (or at least are applied in > > situations where such thinking is called for); that is, making numerous, > > "small", and frequently independent decisions, as you travese their > > branching structures. > > > > Such methods are in direct (diametric) contrast to traditional array > > programming, which encourages and rewards thinking big (and treating all > > elements as equally, as citizens, rather than uniquely, as individuals). > > In concrete terms, we would have to, at the very least, extend or > > introduce tree-specific primitives, and make sure their definitions are > in > > harmony with the existing "array" primitives, and prevailing philosophy > of > > J. No small thing (and, by implication, we'd have to permit our mere > > mortal selves the heresy of modifying scripture: Ken's Dictionary would > > have to be changed). > > > > Anyway, in eons past, I once started collecting my ideas about trees in > J, > > their relationship to boxes, other potential ways how to represent them, > > obstacles to including th
Re: [Jprogramming] Replace one item of a list
We understand the parsing rules as: a =: a to cause =: to have no awareness that 'a' was a part of the far off expression to the right. - Original Message - From: Roger Hui To: Programming forum Cc: Sent: Tuesday, September 9, 2014 12:35 PM Subject: Re: [Jprogramming] Replace one item of a list I don't believe the messages you cited explained it. J syntax consists of word formation as defined by ;: and parsing rules as defined by Section IIE of the dictionary. How is amend-in-place not permitted by either part? On Tue, Sep 9, 2014 at 8:56 AM, Dan Bron wrote: > Ian wrote: > > Then it actually does in-place updating (even though, > > at face value, J syntax does not permit such a thing). > > Roger responded: > > Please explain why this is not permitted by J syntax. > > I believe Ian is expressing a thought recently raised by Erling Hellenas in > [1], which I responded to here: > >http://www.jsoftware.com/pipermail/programming/2014-July/038030.html > > -Dan > > [1] "J and indexed replacement": > http://www.jsoftware.com/pipermail/programming/2014-July/038068.html > > "In most languages indexed replacement is indexed replacement? In J > and > in most functional languages it is not? You get a brand new variable? > So, why give the user the flawed impression he can still do indexed > replacement and do amendments to variables/nouns? And at the same > time > in tacit code we pretend to only have functions? No variables/nouns > to > be amended? Just functional transformations?" > > -- > 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
To address the interface of it, a T: verb a bit similar to $: could transform a nested box structure into an internal efficient representation, but then verbs would still operate as if the data were boxed. T: could be thought of as ragged array implementation as well... variable length items without fills, but then my proposal to make !. on any verb phrase (not defined to fit as something else) to fill with a custom value such as _ or 0 {a., or ideally even _. wasn't seen as useful, even though 50% of this tree implementation's value is specifically designed to work around fills. Having _. as a valid numeric or binary (string) data would be tricky, but the implementation would (just SMOP) length encode the data? Its worth pointing out that there are 2 very distinct uses for/types of trees. 1. is encoding relationships such as containership. Boxes are very good at this other than some performance issues. 2. is providing a structural search or other order to data. I think you are most interested in this use, and Devon's code and links tend to provide good support for this use. Conceptually, structural order trees can also be represented by boxes, but the optimization vector has little to do with avoiding fills. Monad {:: gives a good start to transforming boxed representation into structural paths. - Original Message - From: Dan Bron To: programm...@jsoftware.com Cc: Sent: Tuesday, September 9, 2014 11:50 AM Subject: Re: [Jprogramming] Ragged Array Shapes are Trees Yes, the most obvious candidates for #tree are maximum depth (or breadth), # leaves, or # total nodes. There are others, but the ones I can think of are less compelling. What I was trying to underscore with my message is there are, in fact, multiple definitions available for #tree , all with unique, competing, benefits and drawbacks, but ultimately we can only choose one, and once we choose one, we can't go back. So if we're going to seamlessly integrate trees, as a distinct (non-box) datatype in J, we're going to have to consider how they'll be used, and which definition is "the best". I, personally, don't feel qualified to make that decision (especially since we'll have to ensure all new defintions or extensions are philosophically harmonized with existing definitions as they apply to rectilinear arrays). In other words: this (seamless integration of trees in J) is a worthy objective, but not an easy one to achieve. Personally, I'd be happy to contribute to such an initiative, but I lack the self-confidence to lead it. -Dan - Original Message --- Subject: Re: [Jprogramming] Ragged Array Shapes are Trees From: "'Pascal Jasmin' via Programming" Date: Tue, 9 Sep 2014 07:16:46 -0700 To: "programm...@jsoftware.com" L. might be a candidate. (depth) # of leaves (boxes) might be the most popular ([: +/ 1: S:0) When a tree holds nested records (say customers invoices products bought), then the # of records could be defined as just # . You might want to know number of invoices, but can't naively use L: because a customer might also have nested phone numbers or other data. The point of this blabbering is that sometimes # is domain specific. - Original Message - From: Dan Bron To: programm...@jsoftware.com Cc: Sent: Tuesday, September 9, 2014 9:24 AM Subject: Re: [Jprogramming] Ragged Array Shapes are Trees Here's a question to chew on. What's the # of a tree? - Original Message --- Subject: Re: [Jprogramming] Ragged Array Shapes are Trees From: "Michal D." Date: Mon, 8 Sep 2014 23:04:34 -0700 To: programm...@jsoftware.com Thanks for the links, they make for interesting reading. I agree that the elegance of the solution is the hard part. Nevertheless there have been previous attempts at ragged arrays that we can potentially learn from: nested arrays in APL and K to some degree. I was hoping to find out more about the various approaches that have come up in the past. It's interesting to me that the restriction that one places on what type of ragged arrays are allowed is also exactly the type of raggedness required for representing a shape of such an array (this is an observation not a fact): 1) Arrays are rectangular : a rectangular rank-1 array is enough to describe the shape. 2) Arrays are rectangular except for the last dimension : the shape can be represented by a rank-2 array with singleton entries for the leading axes and a rank-1 array describing the size of each last dimension. 3) Arrays are arbitrarily ragged : the shape can be represented as a tree (ie. a boxed or arbitrarily ragged array). Cheers, Mike On Mon, Sep 8, 2014 at 10:54 AM, Dan Bron wrote: > I expand on this in a little more detail in the Wiki page I linked to, but > (in my view), there are two aspects to address w.r
Re: [Jprogramming] Extend/reduce matrix dimensions
as nice as # inv is, you may find this adverb more flexible and intuitive: insertitem =: 1 : '(u"_ {. ]) , [ , u"_ }. ]' the adverb argument is a verb that tells which item position to insert. The verb argument is dyadic, but can be a constant verb. Add @:] to it to just use y as the argument To insert columns, you would transpose first, to make the columns the items. 1 2: insertitem &.|: 3 3 $ 0 0 0 1 0 0 0 1 0 0 0 1 0 1 2 3 2: insertitem &.|: 3 3 $ 0 0 0 1 0 0 0 2 0 0 0 3 0 1 2: insertitem 1 2: insertitem &.|: 3 3 $ 0 0 0 1 0 0 0 1 0 1 1 1 1 0 0 1 0 deleteitem =: {. , >:@[ }. ] NB. verb 2 deleteitem 2 deleteitem &.|: 1 2: insertitem 1 2: insertitem &.|: 3 3 $ 0 0 0 0 0 0 0 0 0 0 - Original Message - From: Sebastian To: "programm...@jsoftware.com" Cc: Sent: Thursday, September 11, 2014 5:21 AM Subject: [Jprogramming] Extend/reduce matrix dimensions 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] Question on rank conjunction's behavior regarding "unexpected" vector transposition
to get a column sum, all of these would work +/ +/"_1 i.2 4 7 196 204 212 220 228 236 244 +/ +/"2 i.2 4 7 196 204 212 220 228 236 244 +/ +/ i.2 4 7 / or +/ in this case will only "remove" (reduce along) one dimension at a time. - Original Message - From: George Dallas To: programm...@jsoftware.com Cc: Sent: Thursday, September 11, 2014 10:59 AM Subject: [Jprogramming] Question on rank conjunction's behavior regarding "unexpected" vector transposition 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] wait, what?
works in J7 too (152{a.)~ 0 1 2 3 4 5 6 7 8 - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Friday, September 12, 2014 10:09 PM Subject: Re: [Jprogramming] wait, what? 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 -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] OOJ and calling a verb from another locale
locs_z_ =: 1 : 'm loc 18!:5 ' loc_z_=: (,&'_'@[ ,&'_'@, ":@>@])"1 0 'Do' loc 'z' Do_z_ 'Do' locs Do_base_ mean_asd_ =: +/%# data_asd_ =: 1 2 3 ". ('mean' loc <'asd') , ' ' , ": data_asd_ 2 inl_z_ =: (cocurrent@] ".@] [)"1 0 'mean data' inl <'asd' 2 If you are running a string (".) inside a locale, all variable names must be localized. The inl verb lets you run code in another locale reference. For your purposes, you probably want to have the caller use locs to fix its variable locales as it builds the string to send to create. - Original Message - From: Jon Hough To: "programm...@jsoftware.com" Cc: Sent: Monday, September 15, 2014 10:38 AM Subject: [Jprogramming] OOJ and calling a verb from another locale 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
[Jprogramming] wd commands to destroy a control
in Jqt, is there a way to either destroy a control by id, or clear the whole form and add all controls again? (I guess the latter can be done by destroying the form and recreating it) maybe one of the grids can host and delete controls? Some example uses would be: Options that turn off some features. Or say radio buttons that get created/changed based on other selections/data highlighted. -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] wd commands to destroy a control
thank you Bill, in pousse, there is a command wd 'rm' that seems to be applicable to controls (id). It is only enabled for IFJCDROID. The other implementations close the form, and then call a creator function. btw, in j803 on windows 8, there are glpen errors when trying to play the game. (clicking row/col buttons) - Original Message - From: bill lam To: Programming forum Cc: Sent: Tuesday, September 16, 2014 7:52 PM Subject: Re: [Jprogramming] wd commands to destroy a control I agree this is useful. IIRC games/pousse addon used an undocumented jqt wd command which "clear" a top level window (a form), some (or all?) children the parent window contained were destroyed when choosing a different board size. On Sep 17, 2014 12:28 AM, "'Pascal Jasmin' via Programming" < programm...@jsoftware.com> wrote: > in Jqt, is there a way to either destroy a control by id, or clear the > whole form and add all controls again? (I guess the latter can be done by > destroying the form and recreating it) maybe one of the grids can host and > delete controls? > > Some example uses would be: Options that turn off some features. Or say > radio buttons that get created/changed based on other selections/data > highlighted. > -- > 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
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). You can almost always replace a class with a record/struct structure in other languages. In J, the struct is a list of boxes if all of the members are not of homogeneous types, or a list if they are homogeneous. In J, it is no problem if the members are matrices or trees (sub-records). And you can have lists/matrices/trees of records. There is still an organizational advantage to a class approach. It puts complexity in the class in order to avoid complexity by the caller. You can validate each member, write functions that only consider a subset of parameters, and have relatively static state that assists the caller. Keeping the record analogy, it is probably useful to "pre-organize" where changes to that record would be saved instead of using more complex nested hierarchical boxing that groups records on such pre-organized data. There are still non-class approaches to such organization needs. The obvious is to store the database location and connection parameters in a shared/global variable, but then one day you will think you need 2 or more databases. The approach of a global list of databases is still doable, but you are likely to need to rewrite code that assumed just one database. Another source of complexity that has a simpler class solution than caller-managed code can be generally described as mixed pointer/data structures that include various states of binding. 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. Traditional pointers are obtained by passing the name in a string as a parameter. It is clearer to describe the mixed pointer data structure problem with an example: A class allows a simple caller interface to assume that a table is always in memory and contains the latest updated data and indexes, with complex managed state that frees the caller from worrying about it. Even then, though there is still a record approach that can be caller managed, usually with significant performance advantage since the caller knows what he will call next, while a class approach must handle all potential sequences of future calls. tldr; classes are very useful in the normal case where we don't know what we are doing. After a correct program has been completed, the classes look stupid and inefficient. I think adverbs and composition in J allows for simplification of caller managed code, and a set of library functions to process the data structure simplify use for callers further down the chain. - Original Message - From: Dan Bron To: programm...@jsoftware.com Cc: Sent: Wednesday, September 17, 2014 9:42 AM Subject: Re: [Jprogramming] OOJ and calling a verb from another locale John Hough wrote: > But for my specific problem OOP is the way to go I think. Raul wrote: > Out of curiosity, why? John responded: > Well, maybe I don't. But > I have half a dozen variables I want to tie together. Fair enough, but this just pushes the question back, a bit. Ultimately, J programs manage state, as all non-pure-functional languages do (and, arguably, as pure functional languages do, whether or not they admit it). But J does hew closer to the functional paradigm than Java or C++, and correspondingly puts less emphasis on managing state, and consequently, typically J programs manage fewer unique variables than the equivalent program in Java or C++. Add on top of that that J encourages collecting all variables which change together into a single array, and you sometimes end up with very low-variable programs indeed. I can't say that this must be the case for your current application, of course; I can only observe that, as I studied and used J, my style evolved towards using fewer and fewer variables, and placed more emphasis on data transformation through the composition of stateless functions. Not to say "use fewer variables" is better in some generic, universal sense, only that it is probably "J-er". But, then, as Raul is so often and so rightly points out, all design choices are necessarily compromises. -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] OOJ and calling a verb from another locale
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
Re: [Jprogramming] OOJ and calling a verb from another locale
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 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 -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] OOJ and calling a verb from another locale
I've pulled out the term semi-tacit before. tacit -- no : semi-tacit -- no x or y or : inside the quoted code. explicit -- y referenced. - Original Message - From: Dan Bron To: programm...@jsoftware.com Cc: Sent: Wednesday, September 17, 2014 2:23 PM Subject: Re: [Jprogramming] OOJ and calling a verb from another locale Raul wrote: > 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. Though we all "know what it means", it turns out when you really try to put it in words, tacit is, indeed, difficult to define (or at least it was for me; in a 2009 thread, it took me five attempts and not a few false starts to define the word to my own satisfaction). That said, it is (like many things) significantly easier to describe what tacit is *not*, and it is definitely *not* the kind of code which is quoted and then passed to the conjunction : for evaluation (that is, by definition, *explicit* code). In fact, I would say (and I don't expect I'll generate much controversy), that my comfort level in labelling a piece of code "tacit" is diminished in proportion to the degree which it is quoted, or contains quoted code (which will be, or could be, executed later in the evaluation of the expression). That's not an absolute constraint, of course (no more than "tacit" is a binary quality); witness f`g`h@.test , for example. But I would argue that using : --that is, the "explicit" operator-- is a significant, and often fatal, blow to a piece of code's status as tacit. -Dan [1] 2009 thread on the definition of "Tacit": http://www.jsoftware.com/pipermail/programming/2009-August/015771.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
Re: [Jprogramming] OOJ and calling a verb from another locale
Thank you Raul, I withdraw the bug complaint. > So when you say 1 : 'a u ]' returns a probably tacit verb, you are not really saying that 1 :'a u ]' is tacit I'm saying that (a u ]) is a tacit expression, and that is what is returned with u substituted. - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Wednesday, September 17, 2014 6:45 PM Subject: Re: [Jprogramming] OOJ and calling a verb from another locale 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
Re: [Jprogramming] LZ77
patents issued before sept 1996 have already expired. If they were filed in 1994 (but issued up to 1997) they are expired. The condition where the issue date took abnormally long but were filed prior to june 1995 grants 17 years from the issue date. From, http://www.faqs.org/faqs/compression-faq/part1/section-7.html RLE, and LZ77, LZ78 and every other patent mentioned in that paper has expired. - Original Message - From: robert therriault To: programm...@jsoftware.com Cc: Sent: Thursday, September 18, 2014 11:39 AM Subject: Re: [Jprogramming] LZ77 Unintended but not unrelated. :-) And now I think that patent law has already sucked up enough space in this forum on this fine morning, I now return to my regular 'programming' (intended). :-) cheers, bob On Sep 18, 2014, at 8:31 AM, Raul Miller wrote: > 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 some
Re: [Jprogramming] zlib addon thanks
load 'arc/zlib' install_zlib_ '' NB. downloads lib (just needs to be done once) load 'arc/zlib' NB. reload after first dl. - Original Message - From: Devon McCormick To: J-programming forum Cc: Sent: Tuesday, September 23, 2014 1:33 PM Subject: Re: [Jprogramming] zlib addon thanks How do I load this? On Sat, Sep 20, 2014 at 9:25 PM, bill lam wrote: > the windows zlib1.dll binary is actually copied from j701 gtk binary which > was built by Norman Drinkwater. > > zlib_compress also supports an optional left argument between 0 and 9. 0 is > uncompressed, 1 is the fastest, and 9 slowest. > > zlib_uncompress also supports an optional left argument which is the size > of uncompressed data. > On Sep 21, 2014 5:36 AM, "John Baker" wrote: > > > The recently released zlib addon is a big plus for j64 users. > > > > The compiled version is very effective on J text and might prove useful > for > > binary data as well. > > > > The following is a worst case scenario - compressing and uncompressing a > > million random numbers > > > >t =. 100?100 > > > > ts' t -: (3!:2) zlib_uncompress zlib_compress (3!:1) t' > > > > 0.987848 3.77554e7 > > > > > > But on my 64 bit win8.1 machine it gets through the cycle in less than a > > second. On more realistic data performance is much better. > > > > > > Kudos to Bill and anyone else that worked on this addon. > > > > > > -- > > John D. Baker > > bakerj...@gmail.com > > -- > > 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] zlib addon thanks
the addon is available through package manager... Perhaps you have a custom profile that affects load? this is a j803 feature, btw. - Original Message - From: Devon McCormick To: J-programming forum Cc: Sent: Tuesday, September 23, 2014 2:28 PM Subject: Re: [Jprogramming] zlib addon thanks Thanks for the instructions but these fail for me in 64-bit J801 and 802 (and 701) with a "not found" error on '~addons/arc/zlib/zlib.ijs' in all cases. Is there something I need to install other than making sure my J packages are up-to-date? I'm running on Windows 7 - should it be available for this OS? Thanks... On Tue, Sep 23, 2014 at 1:41 PM, 'Pascal Jasmin' via Programming < programm...@jsoftware.com> wrote: > load 'arc/zlib' > install_zlib_ '' NB. downloads lib (just needs to be done once) > load 'arc/zlib' NB. reload after first dl. > > > > > - Original Message - > From: Devon McCormick > To: J-programming forum > Cc: > Sent: Tuesday, September 23, 2014 1:33 PM > Subject: Re: [Jprogramming] zlib addon thanks > > How do I load this? > > On Sat, Sep 20, 2014 at 9:25 PM, bill lam wrote: > > > the windows zlib1.dll binary is actually copied from j701 gtk binary > which > > was built by Norman Drinkwater. > > > > zlib_compress also supports an optional left argument between 0 and 9. 0 > is > > uncompressed, 1 is the fastest, and 9 slowest. > > > > zlib_uncompress also supports an optional left argument which is the size > > of uncompressed data. > > On Sep 21, 2014 5:36 AM, "John Baker" wrote: > > > > > The recently released zlib addon is a big plus for j64 users. > > > > > > The compiled version is very effective on J text and might prove useful > > for > > > binary data as well. > > > > > > The following is a worst case scenario - compressing and uncompressing > a > > > million random numbers > > > > > >t =. 100?100 > > > > > > ts' t -: (3!:2) zlib_uncompress zlib_compress (3!:1) t' > > > > > > 0.987848 3.77554e7 > > > > > > > > > But on my 64 bit win8.1 machine it gets through the cycle in less than > a > > > second. On more realistic data performance is much better. > > > > > > > > > Kudos to Bill and anyone else that worked on this addon. > > > > > > > > > -- > > > John D. Baker > > > bakerj...@gmail.com > > > -- > > > 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 > -- 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
[Jprogramming] suggested language enhancements using . and : with a name
You may already be aware that J's tokenizer keeps . and :'s ending a token as part of that token ;: 'name. 3 4 name::fd' ┌─┬───┬──┬──┐ │name.│3 4│name::│fd│ └─┴───┴──┴──┘ we could take advantage of this tokenizing by invoking special parsing rules based on the presence of such a suffix. Two important specific suggestions: definedname. would apply to the dyadic or modifier definedname the left argument quoted to either the beginning of the line or until a token of [: ( or preferably ]:) or =: is reached. ex. 2 ]: +: @+/ myadv. 3 would be equivalent to: 2 '+: @+/' myadv 3 The need for this is mainly for deferring parsing to an adverb's locale, and avoiding nested quotes. It would also enable a holistic strand notation. It also allows for "line adverbs" that I call macros it would also be possible to nest some of these. example: + ]: insert assign. / eval. 1 2 3 would be equivalent to: + '''insert'' assign /' eval 1 2 3 (6) if definedname. is a noun, then one option is error, but another is appending the quoted left expression to ' definedname' The other suggestion is: name: would invoke name with an implied a: right argument (or ''). This would allow any verb to be used as a noun, and so simplify "lazy noun" evaluations, or just let the verb use default parameters. so coname: f y would be equivalent to: (coname@:] '') f y though its possible to intend for a verb to have a dyadic left argument with null right argument, this is extremely unusual, and so probably doesn't need support. f@mynoun: g y would be equivalent to: (if mynoun is a noun) (f@] mynoun) g y the benefit of this proposal would be to allow verbs that behave as nouns, and also nouns that act as constant verbs. The : suffix makes it consistent with 0: and 1: verbs. A benefit of the interchangeability is that a "lazy noun" (verb that evaluates without parameters but from external state) might "fix itself" (redefine self to a static noun) either after it is first called or under some other condition, and so calling code can benefit from uniform verb/noun calling semantics. -- For information about J forums see http://www.jsoftware.com/forums.htm
[Jprogramming] wd 'setlocale'
is there a way to change syslocalep for a form? change it to a numbered locale? in j803? I am referring to syslocalep. it would simplify having an object create its own form, and handling multiple instances. -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] wd 'setlocale'
thank you Bill. That is a good design. - Original Message - From: bill lam To: 'Pascal Jasmin' via Programming Cc: Sent: Thursday, September 25, 2014 1:00 AM Subject: Re: [Jprogramming] wd 'setlocale' form locale can be numbered locale since day 1. Specifically form locale is the current locale when _executing_ wd'pc' cmd. try the following script, (untested) coclass 'foo' create=: 3 : 0 wd'pc bar closeok;cc btn button;pshow' ) bar_btn_button=: 3 : 0 smoutput coname'' ) cocurrent'base' ''conew 'foo' ''conew 'foo' form locale of objects created are numbered, not foo, the reason why bar_btn_button_foo_ will be called is because foo is in the copath of these objects. Ср, 24 сен 2014, jprogramming написал(а): > is there a way to change syslocalep for a form? change it to a numbered > locale? in j803? > > I am referring to syslocalep. > > it would simplify having an object create its own form, and handling multiple > instances. > -- > 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] Repeated rolling dice
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
Re: [Jprogramming] Repeated rolling dice
there's a small issue with it, (if last roll is a 6) (}:1,6~:x) <;.1 x=. 6 1 6 6 2 3 6 ┌───┬─┬─┬─┐ │6 1│6 6 2│3│6│ └───┴─┴─┴─┘ if you've never seen a use for i.15 0 before, ([: +/ (, >:@?@6:)^:((0=#) +. 6={:)^:_)"1 i.15 0 3 13 3 3 11 1 2 3 5 4 9 4 1 3 1 or (, >:@?@6:)^:((0=#) +. 6={:)^:_"1 i.15 0 1 0 0 2 0 0 6 2 0 5 0 0 5 0 0 1 0 0 5 0 0 1 0 0 2 0 0 2 0 0 4 0 0 6 6 5 6 2 0 6 1 0 2 0 0 - Original Message - From: Devon McCormick To: J-programming forum Cc: Sent: Thursday, September 25, 2014 1:40 PM Subject: Re: [Jprogramming] Repeated rolling dice This looks like a good addition to my growing set of "array-thinking" examples. On Thu, Sep 25, 2014 at 12:32 PM, Roger Hui wrote: > Compared to the other solutions posted so far, I believe it is more > straightforward to do a long sequence of dice rolls and then split it up > according to your specified criteria. The split point are where the > _previous_ roll is _not_ a 6. Thus: > > x=: 1+1e4 ?@$ 6 NB. long sequence of dice rolls >x > 5 4 6 1 5 4 5 6 1 3 5 1 2 3 3 6 5 2 4 5 6 5 5 3 6 2 4 4 1 3 6 4 2 1 5 6 1 6 > 6 6 6 6 5 4 6 1 2 3 2 5 1 2 1 3 2 ... >(}:1,6~:x) <;.1 x > > ┌─┬─┬───┬─┬─┬─┬───┬─┬─┬─┬─┬─┬─┬───┬─┬─┬─┬───┬─┬─┬───┬─┬─┬─┬─┬───┬─┬─┬─┬───┬───┬─┬───┬─┬─┬─┬─┬─┬─┬─┬─┬─┬ > │5│4│6 1│5│4│5│6 1│3│5│1│2│3│3│6 5│2│4│5│6 5│5│3│6 2│4│4│1│3│6 4│2│1│5│6 > 1│6 6 6 6 6 5│4│6 1│2│3│2│5│1│2│1│3│2│ ... > > └─┴─┴───┴─┴─┴─┴───┴─┴─┴─┴─┴─┴─┴───┴─┴─┴─┴───┴─┴─┴───┴─┴─┴─┴─┴───┴─┴─┴─┴───┴───┴─┴───┴─┴─┴─┴─┴─┴─┴─┴─┴─┴ > > > > > On Thu, Sep 25, 2014 at 6:06 AM, Johann Hibschman > wrote: > > > 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 > -- 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] dyad i. on sparse array
I'd hope they were the same too, but here is what is happening: 1 i.~"1 $. #: i.5 1 │ 2 2 │ 1 3 │ 1 4 │ 0 Your result happens due to fill. There could be a !. solution if !. allowed fills to be set for any function (not defined for = or other purpose) or was defined for $. inv - Original Message - From: Ben Gorte - CITG To: "programm...@jsoftware.com" Cc: Sent: Friday, September 26, 2014 8:30 AM Subject: [Jprogramming] dyad i. on sparse array 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
bind is used when the rhs is a noun. @: is an error in such cases. I would not choose to use &> when I know that "0 would work, but its nice that &> will also work with boxed data. - Original Message - From: Johann Hibschman To: Programming forum Cc: Sent: Friday, September 26, 2014 12:05 PM Subject: Re: [Jprogramming] Repeated rolling dice 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] dyadic adverb for ambivalent verb
took me a while to find it, as it is a mistake I often make: nn =: ('a' ('t' adv) ]) : ([ 't' adv ]) - Original Message - From: Brian Schott To: Programming forum Cc: Sent: Friday, October 3, 2014 1:56 PM Subject: [Jprogramming] dyadic adverb for ambivalent verb I have defined an adverb `adv` and a verb `nn`. I want the latter to produce either literally a noun or an executable phrase. The adverb `adv` works for the dyadic case, but not for the monadic case. I want the ambivalent verb *form*, but am willing to adjust other aspects of the adverb and verb. Thanks, adv =: 1 : 0 : x,' ',m,' ',":y ) nn =: ('a' 't' adv ]) : [ 't' adv ] 'z' nn 4 z t 4 nn 4 NB. I want the result: a t y which is a t 4 in this case a t 4 t 4 -- (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] How can I I box items in an array
don't think that is possible, perhaps this helps ,. ;: 'H IJ' ┌──┐ │H │ ├──┤ │IJ│ └──┘ - Original Message - From: Linda Alvord To: programm...@jsoftware.com Cc: Sent: Friday, October 3, 2014 10:00 PM Subject: [Jprogramming] How can I I box items in an array 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 -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Project Euler 85, Python and J
countRects a cool solution that just works without my complete understanding of it either. I'm not convinced of the getSizes range being used though: this is pretty close to 2M 4 %~ */@(, >:) 3 816x 216 So I think a "triangulation" algorithm would be more general than the getSizes filter for >: i.2000 4 %~ */@(, >:) 1 2000x 2001000 4 %~ */@(, >:) 1 1999x 1999000 - Original Message - From: Devon McCormick To: J-programming forum Cc: Sent: Tuesday, October 7, 2014 11:30 AM Subject: Re: [Jprogramming] Project Euler 85, Python and J Hi - "countRects" seems like a bit of a leap. I think I understand "4 %~" because you're overcounting by 4 rotations, but I don't comprehend the magic behind "*/@(,>:)". I see that "(,>:)" concatenates the shape to its increment, e.g. 2 3 3 4 for the input 2 3, but what's the rationale behind this? Thanks, Devon On Tue, Oct 7, 2014 at 7:41 AM, Tikkanz wrote: > Note that 200 x 200 is a bit of an overkill given 3x2 = 2x3 > The following choses the lower triangular of a matrix of the different > sized rectangles to investigate. > getSizes=: ,@(>:/~) # [: ,/ ,"0/~ > getSizes >: i. 5 > > Given the sides of a rectangle you can count the number of rectangles as > follows: > countRects=: 4 %~ */@(, >:) > countRects 2 3 > > Now get the index of the rectangle size with a count closest to 2million > > idxClosest=: (i. <./)@(2e6 |@:- ]) > > > Putting it together > > */@({~ idxClosest@:(countRects"1)) getSizes >: i.200 > > > > On Tue, Oct 7, 2014 at 5:37 PM, Jon Hough wrote: > > > 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: > > = > > def pe85(larg, rarg): count = 0 llist = range(1, larg+1) > > rlist = range(1, rarg+1) > > for l in llist: for r in rlist: count += > > l*r > > return count > > > > if __name__ == "__main__": # test for 2x3 grid, as in question.k > > = pe85(2,3) print "Test value: "+str(k) l1 = range(1,200) # > > 200 lucky guess l2 = range(1,200) bestfit = 1 # just a big > > number area = 0for i in l1:for j in l2: > > diff = abs(200 - pe85(i,j)) if diff > < > > bestfit: area = i*j > > bestfit = diff > > print "AREA is "+str(area) > > > > > > The above script will > give > > the final area of the closest fit to 2 million. (The python code may not > be > > the best). Also I tested all possibilities up to 200x200, which was > chosen > > arbitrarily(~ish). > > Next my J. I go the inner calculation ok (i.e. see the function pe85 > > above). In J I have: > > pe85 =: +/@:+/@:((>:@:i.@:[) *"(0 _) (>:@:i.@:])) > > NB. I know, too brackety. Any tips for improvement appreciated. > > > > > > But from here things get tricky. If I do the calculation over 200x200 > > possibilities I end up with a big matrix, of which I have to find the > > closest value to 2 million, of which then I have to somehow get the (x,y) > > values of and then find the area by x*y. > > > > The main issue is getting the (x,y) from the best fit value of the array. > > > > i.e. If I do pe85"(0)/~ 200, I get a big array, and I know I can get the > > closest absolute value to 2 million but then I need to get the original > > values to multiply together to give the best fit area. Actually I have > > bumped into this issue many times. It is easy enough in a 1-d array,just > do: > > (I. somefunc ) { ]) > > > > or similar to get the index. But for two indices the problem is beyond me > > at the moment. Any help appreciated.Regards,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 > -- 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] what is happening here?
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
Re: [Jprogramming] what is happening here?
From what I understand, pre J6, x. and y. were adverb and conjunction arguments as well as verb arguments. There was a good idea to use u and v instead, but there was a simultaneous hack to keep pre-j6 code working by parsing the old format too. I think it would be good to break that old compatibility. Other than bind, I do not know of any profile code that uses x/y to mean u/v. to add to your examples, 1 (1 : 'smoutput x;y') 2 |value error: y but you can do: 1 (1 : 'smoutput u;y') 2 ┌─┬─┐ │1│2│ └─┴─┘ - Original Message - From: Joe Bogner To: programm...@jsoftware.com Cc: Sent: Wednesday, October 8, 2014 2:39 PM Subject: Re: [Jprogramming] what is happening here? 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⌖=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] Splitting vector
there is: 0 1 0 1 (# ,:~ -.@:[ # ]) i.4 0 2 1 3 or as an adverb that uses a function (of the data) to split the data 2&| 1 : '(-.@:u # [) ,: u # ]' i.8 0 2 4 6 1 3 5 7 - Original Message - From: Andrey Paramonov To: "programm...@jsoftware.com" Cc: Sent: Thursday, October 9, 2014 6:00 PM Subject: [Jprogramming] Splitting vector 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
[Jprogramming] an inverse to I.
I notice that there is no inverse to I. that is defined. Is this an appropriate one? ([: +./ ( 1 ,~ I.)"0) 7 9 0 0 0 0 0 0 0 1 0 1 I. ([: +./ ( 1 ,~ I.)"0) 0 7 9 0 7 9 -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] an inverse to I.
though this works: ([: +/ ( 1 ,~ I.)"0) &> I. each <"1 >:/~ i.3 1 0 0 1 1 0 1 1 1 - Original Message - From: greg heil To: Programming forum Cc: Sent: Saturday, October 11, 2014 12:49 PM Subject: Re: [Jprogramming] an inverse to I. Ii=: [: +./ ( 1 ,~ I.)"0 >:/~ i.3 1 0 0 1 1 0 1 1 1 I. >:/~ i.3 0 0 0 0 1 0 0 1 2 Ii(I. >:/~ i.3) 1 0 0 1 1 0 1 0 1 greg ~krsnadas.org -- from: 'Pascal Jasmin' via Programming to: Programming forum date: 11 October 2014 09:12 subject: [Jprogramming] an inverse to I. I notice that there is no inverse to I. that is defined. Is this an appropriate one? ([: +./ ( 1 ,~ I.)"0) 7 9 0 0 0 0 0 0 0 1 0 1 I. ([: +./ ( 1 ,~ I.)"0) 0 7 9 0 7 9 -- 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] an inverse to I.
Ben's suggestion works for this "weird" use of I. I. 2 3 4 1 0 0 1 1 1 2 2 2 2 3 ([: +/ ( 1 ,~ I.)"0) I. 2 3 4 1 2 3 4 1 But, I just wanted a way to get boolean data. Its pretty straightforward to get trailing 0s ([: +/ ( 1 ,~ I.)"0) 7 9 0 0 0 0 0 0 0 1 0 1 16 $ ([: +/ ( 1 ,~ I.)"0) 7 9 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 though I guess, there is: 1 (7 9 }) 16 $ 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 but I don't believe it can be structured as an inverse to I. because we don't know what the original size (shape) was. If we accept to "unfill" the inverse then this could be faster: I. :. (3 : ' 1 y} (>: >./y) $ 0') inv 7 9 0 0 0 0 0 0 0 1 0 1 I. <: &. (I. :. (3 : ' 1 y} (>: >./y) $ 0')) ([: +/ ( 1 ,~ I.)"0) 7 9 6 8 - Original Message - From: greg heil To: Programming forum Cc: Sent: Saturday, October 11, 2014 2:24 PM Subject: Re: [Jprogramming] an inverse to I. Pascal Indeed taking them one at a time seems to work ... though REB's objection still stands: Ii &> I. each <"1 [2 16$0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 1 greg ~krsnadas.org -- from: 'Pascal Jasmin' via Programming to: "programm...@jsoftware.com" date: 11 October 2014 10:08 subject: Re: [Jprogramming] an inverse to I. though this works: ([: +/ ( 1 ,~ I.)"0) &> I. each <"1 >:/~ i.3 1 0 0 1 1 0 1 1 1 -- from: greg heil to: Programming forum date: 11 October 2014 09:49 subject: Re: [Jprogramming] an inverse to I. Ii=: [: +./ ( 1 ,~ I.)"0 >:/~ i.3 1 0 0 1 1 0 1 1 1 I. >:/~ i.3 0 0 0 0 1 0 0 1 2 Ii(I. >:/~ i.3) 1 0 0 1 1 0 1 0 1 greg ~krsnadas.org -- from: 'Pascal Jasmin' via Programming to: Programming forum date: 11 October 2014 09:12 subject: [Jprogramming] an inverse to I. I notice that there is no inverse to I. that is defined. Is this an appropriate one? ([: +./ ( 1 ,~ I.)"0) 7 9 0 0 0 0 0 0 0 1 0 1 I. ([: +./ ( 1 ,~ I.)"0) 0 7 9 0 7 9 -- 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] An easy one
there is also: 2 (^~ * ^)/\ p: i.6x 72 30375 1313046875 38532504363714053 61870237399093306018139447 which has a winking cat power :P From: Roger Hui To: Programming forum Sent: Friday, October 17, 2014 7:49 PM Subject: Re: [Jprogramming] An easy one 2 */@(^|.)\ p: i.6x 72 30375 1313046875 38532504363714053 61870237399093306018139447 On Fri, Oct 17, 2014 at 4:30 PM, Kip Murray wrote: > 72 30375 1313046875 > > The first of these numbers is (2^3) * (3^2) , the second is (3^5) * (5^3), > and the third is (5^7) * (7^5) . You see the pattern involving successive > primes. > > Write a J expression to produce the above list. --Kip Murray > > > -- > Sent from Gmail Mobile > -- > 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] Insert a 2 dimensional array to a n dimensional array
there is this fairly intuitive approach to2 =: ( [: <"1 [: ,."0/&>/ [: i.@:>: each -~) to =: 2 : 'm ,@:to2 n' 0 0 to 2 2 ┌───┬───┬───┬───┬───┬───┬───┬───┬───┐ │0 0│0 1│0 2│1 0│1 1│1 2│2 0│2 1│2 2│ └───┴───┴───┴───┴───┴───┴───┴───┴───┘ 1 (0 0 to 2 2) } i.4 4 1 1 1 3 1 1 1 7 1 1 1 11 12 13 14 15 to make a verb out of it: toV =: ,@:to2 eval =: 1 : ' a: 1 : m' advswap =: 2 : (':'; 'u x v eval y') 0 0 to 2 2 (1 advswap '}') i.4 4 1 1 1 3 1 1 1 7 1 1 1 11 12 13 14 15 (0 0 toV 2 2) (1 advswap '}') i.4 4 1 1 1 3 1 1 1 7 1 1 1 11 12 13 14 15 From: Sebastian To: "programm...@jsoftware.com" Sent: Tuesday, October 21, 2014 10:04 AM Subject: [Jprogramming] Insert a 2 dimensional array to a n dimensional array 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] An easy Euler Project one (485)
I don't completely understand number of divisors, but note: */@:(>:@{:)"2@(__&q:) 30 8 q: 30 2 3 5 I don't know why number of divisors of 39 would not be 3. Though I guess the divisors are 1 2 3 5 6 10 15 30 So, your d function looks like it should be efficient as long as __ & q: is comparable in speed to just q: */@:(>:@{:)"2@(__&q:) 105600 96 If not, there is this alternative basis for d: */ >: #/.~ q: 105600 96 - Original Message - From: Mike Day To: programm...@jsoftware.com Cc: Sent: Tuesday, October 21, 2014 2:54 PM Subject: Re: [Jprogramming] An easy Euler Project one (485) No takers to the previous posting (below)? 0) Pari GP has a built-in function for number of divisors; J doesn't, although it seems a nice candidate for an extension of p: or q: 1) My fairly crude Pari GP function to solve this problem runs faster than the slightly more elegant although admittedly brute-force J verb(s). The Pari GP solution for the actual Project Euler problem 485 took just under 7 minutes, and is correct, so optimisation isn't really required. I've just received a J solution after 1 hour 20 minutes, also correct. Both run in interactive mode. 2) I did have a go at optimising the GP Pari, using a count array of d-values in the current window (of size 100 000 in the actual problem); that array can be considerably smaller than 100 000; I messed around with forward and backward pointers but it was slower, and buggy. 3) Running a smaller problem under jpm suggests that the bottleneck is the d (number of divisors) verb. S 1e6 1e4 takes about 6.5 seconds of which 6 seconds is spent in "d". 4) So is there a better d verb out there - capable of running efficiently on a vector argument? (Or a p: or q: extension as per 0 above?) Thanks, Mike On 20/10/2014 15:26, Mike Day wrote: > NB. Maximum number of divisors > > NB. Problem 485 > > NB. Published on Saturday, 18th October 2014, 04:00 pm > > NB. Let d(n) be the number of divisors of n. > > NB. Let M(n,k) be the maximum value of d(j) for n ≤ j ≤ n+k-1. > > NB. Let S(u,k) be the sum of M(n,k) for 1 ≤ n ≤ u-k+1. > > NB. > > NB. You are given that S(1000,10)=17176. > > NB. > > NB. Find S(100 000 000,100 000). > > > NB. A brute-force J method: > d =: */@:(>:@{:)"2@(__&q:) > > > S =: +/@:(>./\ d@>:@i.)~/ > > > timer'S 100 1000' NB. NOT the published problem! > > +-+-+ > > |7.769|140671058| > > +-+-+ > > timer'S 100 1' > > +-+-+ > > |7.147|175757800| > > +-+-+ > > > These are faster in a pedestrian Pari GP script, > but it does use the built-in function, "numdiv": > > > (08:10) gp > S(100,1000) > time = 3,302 ms. > %5 = 140671058 > > > (15:13) gp > S(100,1) > time = 2,889 ms. > %6 = 175757800 > > > Curious. > > Mike > > > PS The Pari script: > > S(u,k)= { > rv=vector(k,i,numdiv(i)); \\ rolling vector of "d" values > t=vecmax(rv);curmx=t; > ipos=0; > for(n= k+1, u, > oldrvi=rv[ipos+1]; > newrvi=numdiv(n); > rvi=rv[ipos+1]=newrvi; > if(curmx if(oldrvi==curmx,curmx=vecmax(rv)); > ); > t+=curmx; > ipos=(1+ipos)%k; >); > t; > } > > > > --- 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/8428 - Release Date: 10/21/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] An easy Euler Project one (485)
An optimization of this problem may actually center around M and not d. If the range of M includes a number with only small prime factors, then that will be a candidate for max d within the range of M. if 2^k is within the range, then it is a candidate. 3 * 2^k-1 would have more total divisors 9 * 2^k-2 even more 15 * ... and so on. There is probably a mathematical way of determining the minimum power of 2 that should be considered, but by optimizing M, there is a fairly small number of trial multiplications that need be examined. - Original Message - From: Mike Day To: programm...@jsoftware.com Cc: Sent: Tuesday, October 21, 2014 2:54 PM Subject: Re: [Jprogramming] An easy Euler Project one (485) No takers to the previous posting (below)? 0) Pari GP has a built-in function for number of divisors; J doesn't, although it seems a nice candidate for an extension of p: or q: 1) My fairly crude Pari GP function to solve this problem runs faster than the slightly more elegant although admittedly brute-force J verb(s). The Pari GP solution for the actual Project Euler problem 485 took just under 7 minutes, and is correct, so optimisation isn't really required. I've just received a J solution after 1 hour 20 minutes, also correct. Both run in interactive mode. 2) I did have a go at optimising the GP Pari, using a count array of d-values in the current window (of size 100 000 in the actual problem); that array can be considerably smaller than 100 000; I messed around with forward and backward pointers but it was slower, and buggy. 3) Running a smaller problem under jpm suggests that the bottleneck is the d (number of divisors) verb. S 1e6 1e4 takes about 6.5 seconds of which 6 seconds is spent in "d". 4) So is there a better d verb out there - capable of running efficiently on a vector argument? (Or a p: or q: extension as per 0 above?) Thanks, Mike On 20/10/2014 15:26, Mike Day wrote: > NB. Maximum number of divisors > > NB. Problem 485 > > NB. Published on Saturday, 18th October 2014, 04:00 pm > > NB. Let d(n) be the number of divisors of n. > > NB. Let M(n,k) be the maximum value of d(j) for n ≤ j ≤ n+k-1. > > NB. Let S(u,k) be the sum of M(n,k) for 1 ≤ n ≤ u-k+1. > > NB. > > NB. You are given that S(1000,10)=17176. > > NB. > > NB. Find S(100 000 000,100 000). > > > NB. A brute-force J method: > d =: */@:(>:@{:)"2@(__&q:) > > > S =: +/@:(>./\ d@>:@i.)~/ > > > timer'S 100 1000' NB. NOT the published problem! > > +-+-+ > > |7.769|140671058| > > +-+-+ > > timer'S 100 1' > > +-+-+ > > |7.147|175757800| > > +-+-+ > > > These are faster in a pedestrian Pari GP script, > but it does use the built-in function, "numdiv": > > > (08:10) gp > S(100,1000) > time = 3,302 ms. > %5 = 140671058 > > > (15:13) gp > S(100,1) > time = 2,889 ms. > %6 = 175757800 > > > Curious. > > Mike > > > PS The Pari script: > > S(u,k)= { > rv=vector(k,i,numdiv(i)); \\ rolling vector of "d" values > t=vecmax(rv);curmx=t; > ipos=0; > for(n= k+1, u, > oldrvi=rv[ipos+1]; > newrvi=numdiv(n); > rvi=rv[ipos+1]=newrvi; > if(curmx if(oldrvi==curmx,curmx=vecmax(rv)); > ); > t+=curmx; > ipos=(1+ipos)%k; >); > t; > } > > > > --- 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/8428 - Release Date: 10/21/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] An easy Euler Project one (485)
a complication with the approach is: */ 2 2 2 3 3 5 5 7 11 138600 d */ 2 2 2 3 3 5 5 7 11 144 and so for the ranges starting at 38600 to 63320 there is a greater maximum, and it also appears that for some multiples of 138600, the number of divisors exceeds (for part of the range) of multiples of 83160 a number that simplifies the process is: */ 2 2 2 3 5 7 11 9240 as it allows needing to examine with d only multiples of it. - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Tuesday, October 21, 2014 6:41 PM Subject: Re: [Jprogramming] An easy Euler Project one (485) See also http://oeis.org/A002182 Also Roger Hui's point about a sieve is probably a good one since this problem only needs you to consider prime factors less than 1. Still, those 1229 prime factors multiplied by the 1e8 limit means we would need something on the order of several terabytes of memory for intermediate results if we were to store the entire sieve in the obvious way. So some extra work would be needed, and I'm not sure how that would pan out. -- Raul On Tue, Oct 21, 2014 at 5:27 PM, 'Pascal Jasmin' via Programming < programm...@jsoftware.com> wrote: > a followup, > > q: 83160 > 2 2 2 3 3 3 5 7 11 > > that is the highest d under 100k > >d 83160 *2 > 160 >d 83160 *4 > 192 >d 83160 *5 > > 192 >d 83160 *6 > 200 >d 83160 *8 > 224 >d 83160 *10 > > 240 >d 83160 *13 > 256 >d 83160 *16 > 256 >d 83160 *20 > > 288 >d 83160 *26 > 320 > > > There may be a fairly quick algorithm that allows you to leap from all the > way to 100M, based on such jumps and some likely interesting conjectures ... > > For a number that has a local max of divisors, it is the maximum over the > range 100k below, and 100k above or until next overlapping local max. > There are local spikes along the way, but overall fewer than 2000 (fewer > than 1000 if you get very fancy) numbers to check with d to determine S > over 100M. > > > - Original Message - > From: 'Pascal Jasmin' via Programming > To: "programm...@jsoftware.com" > Cc: > Sent: Tuesday, October 21, 2014 4:37 PM > Subject: Re: [Jprogramming] An easy Euler Project one (485) > > An optimization of this problem may actually center around M and not d. > > If the range of M includes a number with only small prime factors, then > that will be a candidate for max d within the range of M. > > if 2^k is within the range, then it is a candidate. > 3 * 2^k-1 would have more total divisors > 9 * 2^k-2 even more > 15 * ... and so on. > > There is probably a mathematical way of determining the minimum power of 2 > that should be considered, but by optimizing M, there is a fairly small > number of trial multiplications that need be examined. > > > > - Original Message - > From: Mike Day > To: programm...@jsoftware.com > Cc: > Sent: Tuesday, October 21, 2014 2:54 PM > Subject: Re: [Jprogramming] An easy Euler Project one (485) > > No takers to the previous posting (below)? > > 0) Pari GP has a built-in function for number of divisors; >J doesn't, although it seems a nice candidate for an extension of p: > or q: > > 1) My fairly crude Pari GP function to solve this problem runs faster than > the slightly more elegant although admittedly brute-force J verb(s). >The Pari GP solution for the actual Project Euler problem 485 took > just under 7 minutes, and is correct, so optimisation isn't really > required. >I've just received a J solution after 1 hour 20 minutes, also correct. >Both run in interactive mode. > > 2) I did have a go at optimising the GP Pari, using a count array of > d-values in the current window (of size 100 000 in the actual problem); > that array can be considerably smaller than 100 000; I messed around > with forward and backward pointers but it was slower, and buggy. > > 3) Running a smaller problem under jpm suggests that the bottleneck > is the d (number of divisors) verb. > S 1e6 1e4 takes about 6.5 seconds of which 6 seconds is spent in "d". > > 4) So is there a better d verb out there - capable of running efficiently > on a vector argument? (Or a p: or q: extension as per 0 above?) > > Thanks, > > Mike > > On 20/10/2014 15:26, Mike Day wrote: > > NB. Maximum number of divisors > > > > NB. Problem 485 > > > > NB. Published on Saturday, 18th October 2014, 04:00 pm > > > > NB. Let d(n) be the number of divisors of n. > > > > NB. Let M(n,k) be the maximum value of d(j) for n ≤ j ≤ n+k-1. > > > > NB. Let S(u,k
Re: [Jprogramming] An easy Euler Project one (485)
d2 =: */@:>:@:(#/.~)@:q:"0 is a bit quicker than the version you suggested, and though don't really know why, uses much less space. - Original Message - From: Mike Day To: programm...@jsoftware.com Cc: Sent: Tuesday, October 21, 2014 7:33 PM Subject: Re: [Jprogramming] An easy Euler Project one (485) Yes, agreed - I started trying a sieve method earlier today. So far it wasn't doing better than the prime factoring approach using q: though it would no doubt benefit from more careful programming. As I've already got a solution I don't think I'll pursue the sieve method further now. I would have tried that, and also splitting the problem into smaller blocks. Sure you're not tempted to add a primitive for d ? Why is Pari GP quicker here? It's quicker even when my 6Gb machine isn't thrashing for memory. Pascal Jasmin's alternative for d is attractive. In tacit form */@:>:@:(#/.~)@:-.&0"1@:q: is quicker and leaner than */@:(>:@{:)"2@(__&q:) for >: i. 100 though slower albeit still leaner for >: i. 1000 ... Cheers, Mike On 21/10/2014 21:47, Roger Hui wrote: > __ q: 30 > 2 3 5 > 1 1 1 > > The number of divisors are the possible vectors of exponents, which in this > case are {0 1;0 1;0 1. For each prime, if the maximum exponent is e, then > the possible exponents for that prime is 0 1 2 3 ... e-1,e, i.e. the number > of possible exponents is 1+e. > > That's why I suggested using a sieve. Factoring is hard. But if you are > computing the number of divisors of a range, you can avoid factoring > altogether. > > A few weeks ago I came across a neat (but inefficient) expression for the > divisors of n : > > n=. 144 > > ~. n +. 1+i.n > 1 2 3 4 6 8 9 12 16 18 24 36 48 72 144 > __ q: 144 > 2 3 > 4 2 > */ 1 + 4 2 > 15 > # ~. n +. 1+i.n > 15 > > > > On Tue, Oct 21, 2014 at 12:46 PM, 'Pascal Jasmin' via Programming < > programm...@jsoftware.com> wrote: > >> I don't completely understand number of divisors, but note: >> >> */@:(>:@{:)"2@(__&q:) 30 >> 8 >> q: 30 >> 2 3 5 >> >> I don't know why number of divisors of 39 would not be 3. Though I guess >> the divisors are 1 2 3 5 6 10 15 30 >> >> So, your d function looks like it should be efficient as long as __ & q: >> is comparable in speed to just q: >> >> */@:(>:@{:)"2@(__&q:) 105600 >> 96 >> >> If not, there is this alternative basis for d: >> >> */ >: #/.~ q: 105600 >> 96 >> >> >> >> >> - Original Message - >> From: Mike Day >> To: programm...@jsoftware.com >> Cc: >> Sent: Tuesday, October 21, 2014 2:54 PM >> Subject: Re: [Jprogramming] An easy Euler Project one (485) >> >> No takers to the previous posting (below)? >> >> 0) Pari GP has a built-in function for number of divisors; >> J doesn't, although it seems a nice candidate for an extension of p: >> or q: >> >> 1) My fairly crude Pari GP function to solve this problem runs faster than >> the slightly more elegant although admittedly brute-force J verb(s). >> The Pari GP solution for the actual Project Euler problem 485 took >> just under 7 minutes, and is correct, so optimisation isn't really >> required. >> I've just received a J solution after 1 hour 20 minutes, also correct. >> Both run in interactive mode. >> >> 2) I did have a go at optimising the GP Pari, using a count array of >> d-values in the current window (of size 100 000 in the actual problem); >> that array can be considerably smaller than 100 000; I messed around >> with forward and backward pointers but it was slower, and buggy. >> >> 3) Running a smaller problem under jpm suggests that the bottleneck >> is the d (number of divisors) verb. >> S 1e6 1e4 takes about 6.5 seconds of which 6 seconds is spent in "d". >> >> 4) So is there a better d verb out there - capable of running efficiently >> on a vector argument? (Or a p: or q: extension as per 0 above?) >> >> Thanks, >> >> Mike >> >> On 20/10/2014 15:26, Mike Day wrote: >>> NB. Maximum number of divisors >>> >>> NB. Problem 485 >>> >>> NB. Published on Saturday, 18th October 2014, 04:00 pm >>> >>> NB. Let d(n) be the number of divisors of n. >>> >>> NB. Let M(n,k) be the maximum value of d(j) for n ≤ j ≤ n+k-1. >>> >>> NB. Let S(u,k) be the sum of M(n,k)
Re: [Jprogramming] count of consecutive 1s
a couple of tacit versions of this (+/\ - [: >./\ -. * +/\) 0 1 1 1 0 1 1 1 0 1 1 0 0 1 0 0 0 0 1 1 (+/\ ([ - [: >./\ -.@:] * [) ]) 0 1 1 1 0 1 1 1 0 1 1 0 0 1 0 0 0 0 1 1 - Original Message - From: Roger Hui To: Programming forum Cc: Sent: Wednesday, October 22, 2014 1:25 PM Subject: Re: [Jprogramming] count of consecutive 1s x 0 1 1 1 0 1 1 1 0 1 1 0 0 1 0 0 0 0 1 1 s->./\(-.x)*s=.+/\x 0 1 2 3 0 1 2 3 0 1 2 0 0 1 0 0 0 0 1 2 On Wed, Oct 22, 2014 at 10:21 AM, Roger Hui wrote: > You can probably do better than the following, but it'd be useful as a > result checker: > >] x=: 0<20 ?@$ 3 > 0 1 1 1 0 1 1 1 0 1 1 0 0 1 0 0 0 0 1 1 >}. ; +/\&.> <;.1 ] 0,x > 0 1 2 3 0 1 2 3 0 1 2 0 0 1 0 0 0 0 1 2 > > > > > On Wed, Oct 22, 2014 at 10:10 AM, Joe Bogner wrote: > >> This is probably easy but I can't figure it out. How can I count the >> number >> of consecutive 1s? >> >> Another way to think about it is a running sum that resets upon hitting a >> zero >> >> input=:1 0 1 1 1 1 0 1 >> >> expected=: 1 0 1 2 3 4 0 1 >> -- >> 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] An easy Euler Project one (485)
got distracted for the day with this approach: boxes =. (21* >:i.48) ;(14* >:i.77) ;(10* >:i.100) ;(15* >:i.70) ;(125* >:i.8) ; (27* >:i.36) ; (8* >:i.127) ; 6* >: i.168 +/ 991 {.{. >./ ,:&> 0 -.~ each , each 2 ({:@{. #~ [: -~/ {."1)\ each (< 0 4) , each ( 2 (([: {: {:"1) ,.~ ( 0 10 -~ {."1) {~ [: ( <:/ ) {:"1)\ ]) each|:@:( ,: d) each boxes 17184 its the wrong answer, but close :( but it can provide a super quick estimate of 1e8, 1e5 +/ 0 -.~ , &> 2 ({:@{. * [: -~/ {."1)\ each (< (, d) 1e8 -1e5) ,~ each (< 0 128) , each ( 10 ( {.@{. , [: ( >./ ) {:"1)\ ]) each |:@:( ,: d) each < 9240* >: i. <: <: 1e8 <.@% 9240 48390900720 timespacex '+/ 0 -.~ , &> 2 ({:@{. * [: -~/ {."1)\ each (< 0 128) , each ( 10 ( {.@{. , [: ( >./ ) {:"1)\ ]) each |:@:( ,: d) each < 9240* >: i. 1e8 >.@% 9240' 0.0413071 1.85434e6 - Original Message - From: 'Pascal Jasmin' via Programming To: "programm...@jsoftware.com" Cc: Sent: Tuesday, October 21, 2014 7:15 PM Subject: Re: [Jprogramming] An easy Euler Project one (485) a complication with the approach is: */ 2 2 2 3 3 5 5 7 11 138600 d */ 2 2 2 3 3 5 5 7 11 144 and so for the ranges starting at 38600 to 63320 there is a greater maximum, and it also appears that for some multiples of 138600, the number of divisors exceeds (for part of the range) of multiples of 83160 a number that simplifies the process is: */ 2 2 2 3 5 7 11 9240 as it allows needing to examine with d only multiples of it. - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Tuesday, October 21, 2014 6:41 PM Subject: Re: [Jprogramming] An easy Euler Project one (485) See also http://oeis.org/A002182 Also Roger Hui's point about a sieve is probably a good one since this problem only needs you to consider prime factors less than 1. Still, those 1229 prime factors multiplied by the 1e8 limit means we would need something on the order of several terabytes of memory for intermediate results if we were to store the entire sieve in the obvious way. So some extra work would be needed, and I'm not sure how that would pan out. -- Raul On Tue, Oct 21, 2014 at 5:27 PM, 'Pascal Jasmin' via Programming < programm...@jsoftware.com> wrote: > a followup, > > q: 83160 > 2 2 2 3 3 3 5 7 11 > > that is the highest d under 100k > >d 83160 *2 > 160 >d 83160 *4 > 192 >d 83160 *5 > > 192 >d 83160 *6 > 200 >d 83160 *8 > 224 >d 83160 *10 > > 240 >d 83160 *13 > 256 >d 83160 *16 > 256 >d 83160 *20 > > 288 >d 83160 *26 > 320 > > > There may be a fairly quick algorithm that allows you to leap from all the > way to 100M, based on such jumps and some likely interesting conjectures ... > > For a number that has a local max of divisors, it is the maximum over the > range 100k below, and 100k above or until next overlapping local max. > There are local spikes along the way, but overall fewer than 2000 (fewer > than 1000 if you get very fancy) numbers to check with d to determine S > over 100M. > > > - Original Message - > From: 'Pascal Jasmin' via Programming > To: "programm...@jsoftware.com" > Cc: > Sent: Tuesday, October 21, 2014 4:37 PM > Subject: Re: [Jprogramming] An easy Euler Project one (485) > > An optimization of this problem may actually center around M and not d. > > If the range of M includes a number with only small prime factors, then > that will be a candidate for max d within the range of M. > > if 2^k is within the range, then it is a candidate. > 3 * 2^k-1 would have more total divisors > 9 * 2^k-2 even more > 15 * ... and so on. > > There is probably a mathematical way of determining the minimum power of 2 > that should be considered, but by optimizing M, there is a fairly small > number of trial multiplications that need be examined. > > > > - Original Message - > From: Mike Day > To: programm...@jsoftware.com > Cc: > Sent: Tuesday, October 21, 2014 2:54 PM > Subject: Re: [Jprogramming] An easy Euler Project one (485) > > No takers to the previous posting (below)? > > 0) Pari GP has a built-in function for number of divisors; >J doesn't, although it seems a nice candidate for an extension of p: > or q: > > 1) My fairly crude Pari GP function to solve this problem runs faster than > the slightly more elegant although admittedly brute-force J verb(s). >The Pari GP solution for the actual Project Euler problem 485 took > just under 7 minutes, and is correct, so optimisation isn't really >
Re: [Jprogramming] An easy Euler Project one (485)
There is a couple of reasons it fails... First the simplest version uses just one multiple to apply d to. In the case of S(x,10), that number is 6. It relies on the hopeful conjecture that multiples of 6 will have more factors than non multiples, and there is at least one multiple in every range of 10. This is a false conjecture, but it remains somewhat practical. The approach generates hops, and tries to determine M() without calculating it between those hops. It fails in the case of 90 S 10, because d 80= 10 and provides a higher number for M for 2 numbers than the surrounding multiples of 6. +/ 81{. 0 -.~ , 2 ({:@{. #~ [: -~/ {."1)\ ( 0 4) , ( 2 (([: {: {:"1) ,.~ ( 0 10 -~ {."1) {~ [: ( <:/ ) {:"1)\ ]) |:@:( ,: d) 6* >: i.16 754 +/ 90 (>./\ d@>:@i.)~/ 10 758 the boxes approach is just a quick patch to fix by considering independently 6 and 8 multiples, and merging the results, the correct answer is obtained for 90 S 10. Instead of the boxed approach, manipulating the list that d will be applied to include missing key factors would be both faster and cleaner, and allows * to generate sum instead of # The key to the approach, is to obtain S, from this following small table: ( 0 4) , ( 2 (([: {: {:"1) ,.~ ( 0 10 -~ {."1) {~ [: ( <:/ ) {:"1)\ ]) |:@:( ,: d) 6* >: i.16 0 4 2 6 8 6 14 8 20 8 26 9 36 8 38 10 48 8 50 12 60 8 62 12 72 8 74 12 80 12 86 12 The right answer could be derived if the 72 8 entry was replaced with 72 10 (reflecting d 80) There is another unknown bug in my approach in that I end up overestimating somehow 1000 S 10 by adding boxes, when the intent was to prevent underestimating. 2e6 +/@:(>./\ d@>:@i.)~/ 10 448758208 Takes over 10 seconds on my computer but this is instant: +/ > 2({:@{.*[:-~/{."1)\each (<0 128),each(10({.@{.,[:(>./){:"1)\])each |:@:(,:d)each <( ] * [: >: [: i. 2e6<.@% ]) 9240 446883360 Though it needs work on the end range, which could be done by inserting the step size (1e5) into the d build table. - Original Message - From: Mike Day To: programm...@jsoftware.com Cc: Sent: Thursday, October 23, 2014 3:07 PM Subject: Re: [Jprogramming] An easy Euler Project one (485) This might help see where it goes astray: (~.,:#/.~)/:~ 10 >./\ dsieve 1000 4 6 8 9 10 12 14 15 16 18 20 21 24 27 28 30 32 2 12 24 12 16 174 16 20 245 158 102 10 160 10 10 10 10 +/ 10 >./\ dsieve 1000 17176 (~.,:#/.~)/:~991{.{. >./ ,:&> 0 -.~ [...] each boxes 4 6 8 9 10 12 14 15 16 18 20 21 24 27 28 30 32 2 12 22 12 18 174 14 20 247 158 102 10 160 10 10 10 10 NB. despite using fixed width font I've had to hand-align these! I had thought you should be using <.1000%21 14 10 15 125 27 8 6 for the length of each a.p., ie to get >:i.47, >:i.71 etc, but that doesn't work either, providing only 990 elements, and sum 17168 . I can't quite get what you're doing here. (I can talk!) I see that 21* will hoover up all numbers with 3 & 7 as factors, but its list will include numbers also generated by 14* and 15* etc. FWIW,48390900720 is about 5% away from the correct answer. Got to go out now, so that's it for the time being. Mike On 24/10/2014 03:17, 'Pascal Jasmin' via Programming wrote: > got distracted for the day with this approach: > > boxes =. (21* >:i.48) ;(14* >:i.77) ;(10* >:i.100) ;(15* >:i.70) ;(125* > >:i.8) ; (27* >:i.36) ; (8* >:i.127) ; 6* >: i.168 > >+/ 991 {.{. >./ ,:&> 0 -.~ each , each 2 ({:@{. #~ [: -~/ {."1)\ each (< > 0 4) , each ( 2 (([: {: {:"1) ,.~ ( 0 10 -~ {."1) {~ [: ( <:/ ) {:"1)\ ]) > each|:@:( ,: d) each boxes > > 17184 > > its the wrong answer, but close :( > > but it can provide a super quick estimate of 1e8, 1e5 > > +/ 0 -.~ , &> 2 ({:@{. * [: -~/ {."1)\ each (< (, d) 1e8 -1e5) ,~ each (< > 0 128) , each ( 10 ( {.@{. , [: ( >./ ) {:"1)\ ]) each |:@:( ,: d) each < > 9240* >: i. <: <: 1e8 <.@% 9240 > 48390900720 > > timespacex '+/ 0 -.~ , &> 2 ({:@{. * [: -~/ {."1)\ each (< 0 128) , > each ( 10 ( {.@{. , [: ( >./ ) {:"1)\ ]) each |:@:( ,: d) each < 9240* >: i. > 1e8 >.@% 9240' > 0.0413071 1.85434e6 > > > > > - Original Message - > From: 'Pascal Jasmin' via Programming > To: "programm...@jsoftware.com" > Cc: > Sent: Tuesday, October 21, 2014 7:15 PM > Subject: Re: [Jprogramming] An easy Euler Project one (485) > > a complication with the approach is: > > */ 2 2 2 3 3 5 5 7 11 > 138600 > > d */ 2 2 2 3 3 5 5 7 11 > 144 > > and so for th
Re: [Jprogramming] An easy Euler Project one (485)
t; q =. q$~<.n%p NB. extend q for all n(%p) > > i =. I.n$1{.~ - p NB. indices of all multiples of p > > NB. next line, alternative for getting index to amend s and d, > > NB. is slower > > NB. i =. p&*&.>:i.<.n%p > > s =. (<. (i{s) % q{ pl) i } s NB. remove p^q from multiples of p > > d =. ( (i{d) * q + 1) i } d NB. adjust d with contributions from p^q > > p =. 4 p: p NB. next prime > > NB. next line, alternative for next prime, is too slow > > NB. p =. (>:@i.&1 @: >&1 ) s > > > NB. after p=2, s = 1 1 3 1 5 3 7 1 9 5 11 3 13 7 15 1 ... > > NB. after p=2, d = 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 ... > > > NB. after p=3, s = 1 1 1 1 5 1 7 1 1 5 11 1 13 7 5 1 ... > > NB. after p=3, d = 1 2 2 3 1 4 1 4 3 2 1 6 1 2 2 5 ... > > > NB. etc... > > > NB. smoutput p;d,:s > > NB. wd'msgs' > > end. > > > NB. final s is all ones except for primes >: %: n > > NB. double d for every such prime > > d * 1 2{~ s>1 NB. or d * >: s > 1 > > ) > > > Ssieve =: (+/@:(>./\ dsieve )~)/ NB. solves problem 485 in about 5 > minutes. > > Ssieve 1000 10 > > 17176 > > > Mike > > On 22/10/2014 11:48, Mike Day wrote: >> Having floated this boat, here's a sieve method for >> obtaining all numbers of divisors for integers from >> 1 to n: >> >> dsieve =: 3 : 0 >> >> s =. <.>:i.n=.y >> >> d =. n#1 >> >> p =. 2 >> >> while. p < %:n do. >> >> pp =. 1 >> >> np =. (<.n%p)<.<.p^npl =. <.p^.n >> >> q =. np#0 >> >> pl =. p^i.npl+1 >> >> NB. get q = powers of prime p >> >> NB. eg q for p=3 is 1 1 2 1 1 2 1 1 3 ... >> >> while. pp> >> q =. q+np$1{.~-pp >> >> pp =. <.pp*p >> >> end. >> >> NB. q =. +/@:((+/) ($(1{.~-) )"0 ]) pl NB. slower than the explicit loop >> >> q =. q$~<.n%p >> >> i =. I.mask =. n$1{.~ - p >> >> s =. (<. (mask#s) % q{pl) i } s >> >> d =. ((mask#d) * q + 1) i } d >> >> p =. 4 p: p NB. or could search for next non-1 in }.s >> >> end. >> >> d * >:s>1 >> >> ) >> >> >> timer'#dsieve 100' >> >> +-+---+ >> >> |1.446|100| >> >> +-+---+ >> >> >> Pari GP does this in about 1.2 seconds, so a reasonable >> >> comparison. >> >> >> Thanks, >> >> >> Mike >> >> >> On 22/10/2014 00:15, 'Pascal Jasmin' via Programming wrote: >>> a complication with the approach is: >>> >>> */ 2 2 2 3 3 5 5 7 11 >>> 138600 >>> >>> d */ 2 2 2 3 3 5 5 7 11 >>> 144 >>> >>> and so for the ranges starting at 38600 to 63320 there is a greater >>> maximum, and it also appears that for some multiples of 138600, the >>> number of divisors exceeds (for part of the range) of multiples of >>> 83160 >>> >>> a number that simplifies the process is: >>> >>> */ 2 2 2 3 5 7 11 >>> 9240 >>> >>> as it allows needing to examine with d only multiples of it. >>> >>> >>> >>> - Original Message - >>> From: Raul Miller >>> To: Programming forum >>> Cc: >>> Sent: Tuesday, October 21, 2014 6:41 PM >>> Subject: Re: [Jprogramming] An easy Euler Project one (485) >>> >>> See also http://oeis.org/A002182 >>> >>> Also Roger Hui's point about a sieve is probably a good one since this >>> problem only needs you to consider prime factors less than 1. >>> Still, >>> those 1229 prime factors multiplied by the 1e8 limit means we would >>> need >>> something on the order of several terabytes of memory for intermediate >>> results if we were to store the entire sieve in the obvious way. So >>> some >>> extra work would be needed, and I'm not sure how that would pan out. --- 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/8449 - Release Date: 10/25/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] An easy Euler Project one (485)
some math behind it, for 1e5 S y, 1763199 is the maximum y for which 11 is a sufficient prime. q: >: 1e5 -~ 1763200 + 7559 2 2 2 3 3 3 5 7 13 17 this is a d of 256, but boosts the S total by 4, and requires 13. For this difference of 4, the number of d 1e5 less than the max range must be higher than 256, and the next highest d within the 1e5 range must be 252 (4 less than 256) q: >: 1e5 -~ 1763200 + 50399 2 2 2 2 2 2 3 3 5 5 7 17 d >: 1e5 -~ 1763200 + 50399 252 (does not use 13) d 1e5 -~ 1763200 288 Its interesting that the range u can go beyond 4e8 without increasing 13, but from 4e8 to 1e9, it has to go up all the way to 31. I started this post with the statement that there was math... but maybe its luck. - Original Message - From: Mike Day To: programm...@jsoftware.com Cc: Sent: Saturday, October 25, 2014 1:20 PM Subject: Re: [Jprogramming] An easy Euler Project one (485) Wow! 31 is a sufficient maximum for the full Problem 485; 29 isn't. (Trial and error, not mathematical analysis!!!) It takes about 27 seconds with 31 as maximum prime compared to the 45 seconds using all primes <: %: n . Cheers, Mike PS I played around with that "sliding window" article I cited earlier. Not surprisingly, it crawls like a snail with an effort to program it in J. Too loopy. Perhaps I could tacitise it, but not easy and hardly worth the effort. On 25/10/2014 17:51, 'Pascal Jasmin' via Programming wrote: > > combined our approaches with a simple modification to dsieve > > add 2 lines to top of function: > ( %: y) dsieve y > : > > change the while line to: > > while. p <: x do. > > for 1e5 S 4e8, you do not need to look at primes higher than 13, and so this > runs in 9 seconds > > timespacex '10 ([: +/ >./\) 13 dsieve 4000' > 9.74692 2.51659e9 > > Smaller ranges (y) increase the required prime relative to max u (x)... 1e4 S > 4e6 requires primes up to 23 > > 1 ([: +/ >./\) 23 dsieve 400 > 932689064 > > There is probably a mathematical relationship but a simple conjecture would > be that if including the next prime in the sieve loop does not increase the S > total, then no other prime above that would either. So there could be a > built in loop short circuit. > > > > From: Mike Day > To: programm...@jsoftware.com > Sent: Saturday, October 25, 2014 6:29 AM > Subject: Re: [Jprogramming] An easy Euler Project one (485) > > > FWIW, I've finally cracked the minute for the full problem > using the improved sieve below. It takes about 45 sec on > my laptop. > > 3 points: > 0) Problem 485 solvers' discussion reveals this discussion about > maxima in a sliding window: > http://richardhartersworld.com/cri/2001/slidingmin.html > > I doubt if it outperforms J's elegant method, eg > 10 >./\ v > but I might have a look. > > 1) Several solvers seemed to have used a sieve, others brute- > force, as I did originally. Some discussion of the windowing, > including (0) above. > > 2) I'm puzzled why this method of producing an arithmetic > progression of indices into an array > i =. <:+/\p#~<.n%p > is quicker than the more obvious: > i =. I.n$1{.~ - p > > Here's the improved sieve; I expect there will be gratuitous > line-throws again: > > dsieve =: 3 : 0 > > NB. SLIGHTLY FASTER WITH m THAN s IN PREVIOUS VN > > m =. 1#~n =. y NB. running product array > > d =. m NB. number of divisors array > > NB. every number i is a product of pij^qij for some distinct primes, pij > > NB. required di is the product of (qij+1) > > p =. 2 NB. seed first prime candidate > > while. p <: %:n do. > > np =. (<.n%p)<. <. p^npl =. <: >.p^.n > > pl =. <. p^i.npl+1 > > > NB. get q = powers of prime p in multiples of p > > NB. eg q for p=3 is 1 1 2 1 1 2 1 1 3 for n < 27^2 > > NB. cf 3 6 9 12 15 18 21 24 27 > > q =. (}: , >:@{:)@:($~ (p * #))^:(0>.npl-1)1 > > q =. q$~<.n%p NB. extend q for all n(%p) > > NB. i =. I.n$1{.~ - p NB. indices of all multiples of p > > NB. next line, alternative for getting index to amend s and d, > > NB. is FASTER! > > i =. <:+/\p#~<.n%p > > > m =. (<. (i{m) * q{ pl) i } m NB. embed p^q for all multiples of p > > d =. ( (i{d) * q + 1) i } d NB. adjust d with contributions from p^q > > > NB. first three sets of m & d > > NB. +-++ > > NB. |2|1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2| > > NB. | |1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2| &g
Re: [Jprogramming] datetime addin not working
The 3 key points about locales: 1. The default console locale is 'base'. You do not need to access names with the name_base_ modifier if in current locale. 2. In code (or console) if you issue the line cocurrent 'newlocale' then all subsequent definitions use that locale as the current (and so you do not need the _newlocale_ accessor for those names while "in" that locale. 3. The 'z' locale is normally available to all others. locales have search paths such that if a name is not found within it, it searches through its search path to find the first match in path, and uses that name. The z locale defaults to be in the search path of all other locales. - Original Message - From: Kyle M. Rudden To: "programm...@jsoftware.com" Cc: Sent: Sunday, October 26, 2014 8:51 AM Subject: Re: [Jprogramming] datetime addin not working Got it - thanks. Locales are an area that I have not explored yet. Kyle Rudden -Original Message- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of tom arneson Sent: Sunday, October 26, 2014 8:43 AM To: programm...@jsoftware.com Subject: Re: [Jprogramming] datetime addin not working That noun is in a locale: rgsdatetime MS0Date_rgsdatetime_ 36522 -Original Message- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Kyle M. Rudden Sent: Sunday, October 26, 2014 06:46 To: programm...@jsoftware.com Subject: Re: [Jprogramming] datetime addin not working Script is loading, without error message, but cannot access content: load 'types/datetime' MS0date |value error: MS0date load 'types/datetime/test/test_datetime' test_datetime passed load 'c:/users/krudden/j64-802/addons/types/datetime/datetime.ijs' MS0date |value error: MS0date Kyle Rudden -Original Message- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Tikkanz Sent: Sunday, October 26, 2014 1:03 AM To: Programming JForum Subject: Re: [Jprogramming] datetime addin not working Agreed. I was able to load and run the test script successfully in both j64 8.02 and 8.03. load 'types/datetime' load 'types/datetime/test/test_datetime' test_datetime passed We will need more information to help. On Sun, Oct 26, 2014 at 3:53 PM, chris burke wrote: > I don't see any obvious problem with datetime. > > What did you try, and with what result? > > On Sat, Oct 25, 2014 at 8:30 AM, Kyle M. Rudden < > kyle.rud...@kr-consulting.com> wrote: > > > I wanted to convert some Excel dates to J, and some other > > functionality found in the datetime addin, but can't seem to get the addin to work. > > It lists as installed, and I have also installed the "numeric" addin > > it called for . > > No problems with other standard addins. > > I took the MS0Date value I wanted from the datetime.ijs file, so I > > have a work around, but still not sure why the addin would not work. > > Not critical for what I am doing right now, but just wanted to > > mention > it. > > Running 8.02 on Windows 7 64. > > > > Regards > > Kyle Rudden > > > > > > -- 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
[Jprogramming] 32 bit mersenne twister in 64 bit J
The algorithm for ? generation (mode 2 in NRG select) changed in J-64. Is there a way to import j.dll functions so as to use the old version? see http://www.jsoftware.com/pipermail/programming/2014-June/037583.html That request aside, I was able to create some portable (32 and 64 bit identical streams) random generation code. Some of which are quite fast. http://www.jsoftware.com/jwiki/PascalJasmin/portable%20and%20possibly%20secure%20RNGs There are also some versions that may be applicable to cryptography. -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] 32 bit mersenne twister in 64 bit J
I was hoping the 32 bit functions somehow exist, and there is an abracadabra that unlocks them, in 64 bit J. - Original Message - From: Joe Bogner To: programm...@jsoftware.com Cc: Sent: Wednesday, October 29, 2014 7:08 AM Subject: Re: [Jprogramming] 32 bit mersenne twister in 64 bit J Pascal, is your question whether it's possible to call an older version of the j.dll? If so, I don't see why not. See http://jsoftware.com/wsvn/addons/trunk/general/misc/jdll.ijs for an example of calling j.dll. It seems like you would just need to point to the path of the older version On Tue, Oct 28, 2014 at 8:17 PM, 'Pascal Jasmin' via Programming < programm...@jsoftware.com> wrote: > The algorithm for ? generation (mode 2 in NRG select) changed in J-64. Is > there a way to import j.dll functions so as to use the old version? > > see http://www.jsoftware.com/pipermail/programming/2014-June/037583.html > > > That request aside, I was able to create some portable (32 and 64 bit > identical streams) random generation code. Some of which are quite fast. > > > http://www.jsoftware.com/jwiki/PascalJasmin/portable%20and%20possibly%20secure%20RNGs > > There are also some versions that may be applicable to cryptography. > -- > 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] 32 bit mersenne twister in 64 bit J
The issue has to do with the algorithm being used in J32 and J64 for mersenne twister (rng mode 2 which is default). They are based on different specs (MT19933-32 vs MT19933-64), but both exist in the source code. The "problem" is that they generate different streams based on whether they are compiled to 32 or 64 bits. It is possible to get the same random stream using gbflip algorithm (mode 1) in 32 and 64 bit modes with: RawRnd31 (] {. 2147483647 ,@:(17 b. ,. [ 17 b. >:@[ <.@%~ ]) [: (128!:4) 2 >.@%~ ])"0 on J64, and ((] {. [: , [: }:("1) _3 ,\ [: 128!:(4) 3 * 2 >.@%~ ])"0) on J32. Its not too hard to build other RNGs that build on this result (in linked essay) including MT19933-32 but it won't be as fast as J's internal implementation of MT. - Original Message - From: Joe Bogner To: programm...@jsoftware.com Cc: Sent: Wednesday, October 29, 2014 11:20 AM Subject: Re: [Jprogramming] 32 bit mersenne twister in 64 bit J Ah, not without some form of process interop. A 64 bit app can't invoke a 32-bit dll http://msdn.microsoft.com/en-us/library/windows/desktop/aa384231(v=vs.85).aspx On 64-bit Windows, a 64-bit process cannot load a 32-bit dynamic-link library (DLL). Additionally, a 32-bit process cannot load a 64-bit DLL. However, 64-bit Windows supports remote procedure calls (RPC) between 64-bit and 32-bit processes (both on the same computer and across computers). On 64-bit Windows, an out-of-process 32-bit COM server can communicate with a 64-bit client, and an out-of-process 64-bit COM server can communicate with a 32-bit client. Therefore, if you have a 32-bit DLL that is not COM-aware, you can wrap it in an out-of-process COM server and use COM to marshal calls to and from a 64-bit process. On Wed, Oct 29, 2014 at 10:46 AM, 'Pascal Jasmin' via Programming < programm...@jsoftware.com> wrote: > I was hoping the 32 bit functions somehow exist, and there is an > abracadabra that unlocks them, in 64 bit J. > > > - Original Message - > From: Joe Bogner > To: programm...@jsoftware.com > Cc: > Sent: Wednesday, October 29, 2014 7:08 AM > Subject: Re: [Jprogramming] 32 bit mersenne twister in 64 bit J > > Pascal, is your question whether it's possible to call an older version of > the j.dll? If so, I don't see why not. See > http://jsoftware.com/wsvn/addons/trunk/general/misc/jdll.ijs for an > example > of calling j.dll. It seems like you would just need to point to the path of > the older version > > > > > On Tue, Oct 28, 2014 at 8:17 PM, 'Pascal Jasmin' via Programming < > programm...@jsoftware.com> wrote: > > > The algorithm for ? generation (mode 2 in NRG select) changed in J-64. > Is > > there a way to import j.dll functions so as to use the old version? > > > > see http://www.jsoftware.com/pipermail/programming/2014-June/037583.html > > > > > > That request aside, I was able to create some portable (32 and 64 bit > > identical streams) random generation code. Some of which are quite fast. > > > > > > > http://www.jsoftware.com/jwiki/PascalJasmin/portable%20and%20possibly%20secure%20RNGs > > > > There are also some versions that may be applicable to cryptography. > > -- > > 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] 32 bit mersenne twister in 64 bit J
That would be helpful. It would work for mode 3 (DX-1597-4d), and it would make it possible to include MT19937-32 as mode 5 with unchanged source for that algorithm for whatever compilation target. From: bill lam To: 'Pascal Jasmin' via Programming Sent: Thursday, October 30, 2014 11:15 AM Subject: Re: [Jprogramming] 32 bit mersenne twister in 64 bit J IMO it will be much simplier if you can persuade Roger Hui to add an adhoc fit (!.) for ? such that it will generate 32-bit random numbers even for 64-bit platforms. Вт, 28 окт 2014, jprogramming написал(а): > The algorithm for ? generation (mode 2 in NRG select) changed in J-64. Is > there a way to import j.dll functions so as to use the old version? > > see http://www.jsoftware.com/pipermail/programming/2014-June/037583.html > > > That request aside, I was able to create some portable (32 and 64 bit > identical streams) random generation code. Some of which are quite fast. > > http://www.jsoftware.com/jwiki/PascalJasmin/portable%20and%20possibly%20secure%20RNGs > > There are also some versions that may be applicable to cryptography. > -- > 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] 32 bit mersenne twister in 64 bit J
I found a function for gbflip that converts the 64 bit random number stream into 2/3rds of J32's 32 bit stream. For mode 3, I can get a few common numbers, but can't guess a conversion. For mode 2, as I understand it, the seed is a 19997 bit number coded as an array of smaller numbers (bytes). As I understand it, the 32 bit algorithm would make a 32 bit mapping of that seed to a 32 bit number even if it were compiled on 64 bits. The different 64 bit algorithm has no 32 bit conversion of result to the 32 bit algorithm. Its possible that on 64 bit systems, the 32 bit algorithm does need an extra machine word size check that fit might provide. I think Bill's suggestion is more related to modes other than 2, though in the case of MT there also needs to be an extra mode to reflect the 32 bit algorithm. On another note, since (128!:4) returns a 64 bit number on J-64 does this mean the upper bound documentation is outdated for modes 2 3 and 4? (It appears as though for mode 1, there is a direct mapping of 62 bit numbers to 31 bit) One option would be to change (128!:4) to return the 32 bit documented upper bounds of their functions, and then have special 64 bit modes for the current behaviour that would need updated documentation. From: Devon McCormick To: J-programming forum Sent: Friday, October 31, 2014 9:13 AM Subject: Re: [Jprogramming] 32 bit mersenne twister in 64 bit J Since there's already a way to specify the RNG to use, it might make sense to enhance this to include 32- and 64-bit versions rather than use fit. On Thu, Oct 30, 2014 at 12:14 PM, 'Pascal Jasmin' via Programming < programm...@jsoftware.com> wrote: > That would be helpful. It would work for mode 3 (DX-1597-4d), and it > would make it possible to include MT19937-32 as mode 5 with unchanged > source for that algorithm for whatever compilation target. > > > > ________________ > From: bill lam > To: 'Pascal Jasmin' via Programming > Sent: Thursday, October 30, 2014 11:15 AM > Subject: Re: [Jprogramming] 32 bit mersenne twister in 64 bit J > > > IMO it will be much simplier if you can persuade Roger Hui to > add an adhoc fit (!.) for ? such that it will generate 32-bit > random numbers even for 64-bit platforms. > > > > > Вт, 28 окт 2014, jprogramming написал(а): > > The algorithm for ? generation (mode 2 in NRG select) changed in J-64. > Is there a way to import j.dll functions so as to use the old version? > > > > see http://www.jsoftware.com/pipermail/programming/2014-June/037583.html > > > > > > That request aside, I was able to create some portable (32 and 64 bit > identical streams) random generation code. Some of which are quite fast. > > > > > http://www.jsoftware.com/jwiki/PascalJasmin/portable%20and%20possibly%20secure%20RNGs > > > > There are also some versions that may be applicable to cryptography. > > -- > > 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 > -- 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] shorter way to prefix lines altenatively?
nice, can kind of work for odd rows too: (1 1;1 2) ,(L:0) _2[\ <"1 i.4 4 ┌─┬───┐ │1 1 0 1 2 3 │1 1 4 5 6 7│ ├─┼───┤ │1 2 8 9 10 11│1 2 12 13 14 15│ └─┴───┘ or (1 1;1 2) ,(L:0) |: _2[\ <"1 i.4 4 ┌───┬───┐ │1 1 0 1 2 3│1 1 8 9 10 11 │ ├───┼───┤ │1 2 4 5 6 7│1 2 12 13 14 15│ └───┴───┘ (1 1;1 2) ,(L:0) _3[\ <"1 i.5 4 ┌───┬───┬─┐ │1 1 0 1 2 3│1 1 4 5 6 7│1 1 8 9 10 11│ ├───┼───┼─┤ │1 2 12 13 14 15│1 2 16 17 18 19│1 2 │ └───┴───┴─┘ From: R.E. Boss To: programm...@jsoftware.com Sent: Monday, November 3, 2014 9:35 AM Subject: Re: [Jprogramming] shorter way to prefix lines altenatively? ;('A:';'B:'),L:0 "1 [_2[\<;.2 t A:abc B:defg A:hijkl B:erws A:opqow B: A:sdfsdf B:dofi R.E. Boss (Add your info to http://www.jsoftware.com/jwiki/Community/Demographics ) > -Original Message- > From: programming-boun...@forums.jsoftware.com [mailto:programming- > boun...@forums.jsoftware.com] On Behalf Of Roger Hui > Sent: maandag 3 november 2014 13:01 > To: Programming forum > Subject: Re: [Jprogramming] shorter way to prefix lines altenatively? > > ; ((('A:';'B:') $~ #) ,&.> ]) <;.2 t > > On Mon, Nov 3, 2014 at 3:50 AM, June Kim (김창준) > wrote: > > > Hello > > > > > > I am looking for a shorter and more elegant way to do the following given a > > string t: > > > >t=. 0 :0 > > > > abc > > > > defg > > > > hijkl > > > > erws > > > > opqow > > > > > > sdfsdf > > > > dofi > > > > ) > > > >,&:>/ ,(,.~ ('A:';'B:') $~ #) ,.<;. 2 t > > > > A:abc > > > > B:defg > > > > A:hijkl > > > > B:erws > > > > A:opqow > > > > B: > > > > A:sdfsdf > > > > B:dofi > > -- > > 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] Need analog strcmp-function verb
/: doesn't really work for unicode, unless you convert unicode into an integer mapping and then use that as x for /: /: has the advantage of working with boxed data, or "records"/lists With those limitations we could think of using ,:&(a.&i.)&": to build numeric arrays to compare, but that runs into rank quirks with single "character" left sides, so boxing seems simpler with: '3'([: ,/&> ,&<&(a.&i.)&":) '3a' 51 0 51 97 You gain the "benefit" of being able to treat original integers as strings. comparing then with < and > is a little harder due to handling tie breaks, and you are duplicating the real work of /: in doing so? '3'([: * [: -~/ 1 i."1~ [: (/ ) [: ,/&> ,&<&(a.&i.)&":) '3a' - Original Message - From: bill lam To: Programming forum Cc: Sent: Thursday, November 13, 2014 8:11 AM Subject: Re: [Jprogramming] Need analog strcmp-function verb Sorting is an expensive operation. Could it be only once? On Thu, Nov 13, 2014 at 8:43 PM, Henry Rich wrote: >strcmp =: (\: -&{. /:)@,&< > > Henry Rich > > > On 11/13/2014 5:35 AM, Jan-Pieter Jacobs wrote: >> >> J has total ordering (meaning anything can be sorted): >> http://www.jsoftware.com/jwiki/Essays/The%20TAO%20of%20J >> >> Using the verbs listed there you can define: >> >> strcmp =: _1 0 1 #~ gt , eq , lt >>gt =: 1 0 -: /:@,&< >>eq =: -:!.0 >>lt =: 1 0 -: \:@,&< >> >> ('a a a ac') strcmp&>&:;: 'ab aa a ab' >> >> 1 >> >> 1 >> >> 0 >> >> _1 >> >> >> 2014-11-13 11:16 GMT+01:00 Sergey Kamenev : >> >>> Hello folks! >>> >>> Need strcmp verb >>> http://php.net/manual/function.strcmp.php >>> >>> 'a' strcmp 'ab' >>> 1 >>> >>> 'a' strcmp 'aa' >>> 1 >>> >>> 'a' strcmp 'a' >>> 0 >>> >>> 'ac' strcmp 'ab' >>> _1 >>> >>> May be you have implementation of this verb? >>> >>> Thank you! >>> Sergey >>> -- >>> 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] Need analog strcmp-function verb
what I meant is there is no automagical colating sequence u: 197 65 ÅA (1 u: 'B') (\: -&{. /:)@,&< 4 u: 197 1 (u: 66) (\: -&{. /:)@,&< u: 197 1 'B' (\: -&{. /:)@,&< 'A' _1 I understand (recently learned) that universal collating sequences don't exist as Swedes and Germans sort differently. - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Thursday, November 13, 2014 12:09 PM Subject: Re: [Jprogramming] Need analog strcmp-function verb I was initially puzzled by what you meant by "/: doesn't really work for unicode". But then I realized, that while things like... $u: 9824 9829 9830 9827 4 u: 9824 9829 9830 9827 ♠♥♦♣ /: u: 9824 9829 9830 9827 0 3 1 2 ... do work, it is possible to sort the octets of the utf-8 representation of unicode and that can result in a non-unicode sequence of octets. /: 8 u: u: 9824 9829 9830 9827 1 4 7 10 2 11 5 8 0 3 6 9 /:~ 8 u: u: 9824 9829 9830 9827 [garbage] Then again, you do not need to sort the octets and expect them to be meaningful unicode. /: 7 u: 8 u: u: 9824 9829 9830 9827 0 3 1 2 That said, this kind of a distinction matters quite a lot to implementers and is likely to escape the awareness of people doing the specifications. Thanks, -- Raul On Thu, Nov 13, 2014 at 11:35 AM, 'Pascal Jasmin' via Programming wrote: > /: doesn't really work for unicode, unless you convert unicode into an > integer mapping and then use that as x for /: > > /: has the advantage of working with boxed data, or "records"/lists > > With those limitations we could think of using ,:&(a.&i.)&": to build numeric > arrays to compare, but that runs into rank quirks with single "character" > left sides, so boxing seems simpler with: > >'3'([: ,/&> ,&<&(a.&i.)&":) '3a' > 51 0 > 51 97 > > > You gain the "benefit" of being able to treat original integers as strings. > > comparing then with < and > is a little harder due to handling tie breaks, > and you are duplicating the real work of /: in doing so? > > '3'([: * [: -~/ 1 i."1~ [: (/ ) [: ,/&> ,&<&(a.&i.)&":) '3a' > > > - Original Message - > From: bill lam > To: Programming forum > Cc: > Sent: Thursday, November 13, 2014 8:11 AM > Subject: Re: [Jprogramming] Need analog strcmp-function verb > > Sorting is an expensive operation. Could it be only once? > > On Thu, Nov 13, 2014 at 8:43 PM, Henry Rich wrote: >>strcmp =: (\: -&{. /:)@,&< >> >> Henry Rich >> >> >> On 11/13/2014 5:35 AM, Jan-Pieter Jacobs wrote: >>> >>> J has total ordering (meaning anything can be sorted): >>> http://www.jsoftware.com/jwiki/Essays/The%20TAO%20of%20J >>> >>> Using the verbs listed there you can define: >>> >>> strcmp =: _1 0 1 #~ gt , eq , lt >>>gt =: 1 0 -: /:@,&< >>>eq =: -:!.0 >>>lt =: 1 0 -: \:@,&< >>> >>> ('a a a ac') strcmp&>&:;: 'ab aa a ab' >>> >>> 1 >>> >>> 1 >>> >>> 0 >>> >>> _1 >>> >>> >>> 2014-11-13 11:16 GMT+01:00 Sergey Kamenev : >>> >>>> Hello folks! >>>> >>>> Need strcmp verb >>>> http://php.net/manual/function.strcmp.php >>>> >>>> 'a' strcmp 'ab' >>>> 1 >>>> >>>> 'a' strcmp 'aa' >>>> 1 >>>> >>>> 'a' strcmp 'a' >>>> 0 >>>> >>>> 'ac' strcmp 'ab' >>>> _1 >>>> >>>> May be you have implementation of this verb? >>>> >>>> Thank you! >>>> Sergey >>>> -- >>>> 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] Setting arbitrary leaf of tree
there is no }:: This conjunction seems to enable a solution for most similar problems. It is set to take verbs only, and you get to learn a lot about conjunctions and each by practising with it. :P amend_z_ =: 2 : 0 NB. v is n or n{"num s=. v"_ y (u (s{y)) (s}) y : s=. v"_ y (x u (s{y)) (s}) y ) 'xyz'"_ each amend 1 each amend 1 each amend 2 'the cat' ; 'sat' ; < 'on' ; < ('the';'mat') A more tacit variation, that seems to always work so far: hook =: 2 : '([: u v) : (u v) ' amendT =: 2 : ' u hook (n { ]) n} ]' 'xyz'"_ each amendT 1 each amendT 1 each amendT 2 'the cat' ; 'sat' ; < 'on' ; < ('the';'mat') This could be expanded as the reverse (|.) of the {:: notation - Original Message - From: Sergey Kamenev To: programm...@jsoftware.com Cc: Sent: Thursday, November 13, 2014 1:28 PM Subject: [Jprogramming] Setting arbitrary leaf of tree I reading http://www.jsoftware.com/help/learning/32.htm This chapter about boxed trees. J have beatiful verb Fetch {:: This verb get any leaf by path. I need verb for setting any selected leaf by path. NB. Tree ] T =: 'the cat' ; 'sat' ; < 'on' ; < ('the';'mat') ND. Get leaf by path (2; 1; 1) {:: T mat How to change only one leaf in tree e.g. from "mat" to "xyz" without re-creating the tree? Thank you! Sergey -- 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] Windows Clipboard
wdclippaste wd@('clippaste'"_) ::(''"_) I don't know the other one, but wd 'clipcopy 1 2 3' puts '1 2 3' on clipboard. - Original Message - From: Leigh J. Halliwell To: programm...@jsoftware.com Cc: Sent: Thursday, November 13, 2014 4:31 PM Subject: [Jprogramming] Windows Clipboard Dear J Forum: I've upgraded to J802, but now my scripts that invoked wdclipread and wdclipwrite can't find those verbs. Are they still available in some library, or does J8 use another method for passing data to and from the clipboard? Thanks for the help. Sincerely, Leigh Leigh Joseph Halliwell, FCAS, MAAA Chief Manager L. J. Halliwell, LLC P. O. Box 2022 Collegedale, TN 37315 423-296-2739 423-605-5789 cell mailto:lhalliw...@epicactuaries.com> le...@lhalliwell.com http://www.lhalliwell.com> www.lhalliwell.com This communication is intended solely for the use of the individual to whom or the entity to which it is addressed. It may contain information that is privileged, confidential, and exempt from disclosure under applicable law. If you are neither the intended recipient, nor the employee, nor the agent responsible for delivering the communication to the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone or email, delete the communication from any computer or other electronic storage media, and destroy all other copies in your possession. -- 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] projecting onto a fixed grid
here is a typical way to get the bin count (~. ,: #/.~) 5 10 20 # 100 200 300 100 200 300 5 10 20 you can obtain a "stretch factor" with e. 5 10 20 e.~ 5 * i.5 0 1 1 0 1 then apply the stretch factor with # inv 100 200 300 # inv~ 5 10 20 e.~ 5 * i.5 0 100 200 0 300 all together: (5 * i.5) ({.@:] #inv~ [ e. {:@:]) (~. ,: #/.~) 5 10 20 # 100 200 300 0 100 200 0 300 - Original Message - From: Joe Bogner To: programm...@jsoftware.com Cc: Sent: Friday, November 14, 2014 6:04 AM Subject: Re: [Jprogramming] projecting onto a fixed grid I would probably do this: (ys,0) {~ xs i. xGrid 0 100 200 0 300 On Thu, Nov 13, 2014 at 11:08 AM, Johann Hibschman wrote: > I'm trying to figure out how best to project some values (think counts > for particular bins) onto a fixed grid of bins (think each bin in > order). > > For example, this does what I want: > >xGrid=: 0 5 10 15 20 >xs=: 5 10 20 >ys=: 100 200 300 >ys (xGrid i. xs)}0*xGrid > 0 100 200 0 300 > > It seems a little cumbersome, though, so I was wondering if there's a > better way. > > 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] Setting arbitrary leaf of tree
that is a cool function. Similar to Raul's for those who had problems copying it: applyintree =: 2 : 0 if. #n do. ((u applyintree (}.n)) L:_1 ({.n){y) ({.n)} y else. u y end. : NB. The rank is s,0 where s is the surplus of x-rank over y-rank. This causes NB. the cells of y to be matched up with the largest appropriate blocks x. This NB. is necessary because it is impossible to change the shape of the values being modified if. #n do. (x u applyintree (}.n) L:_ _1"(0 (,~ >.) x -&(#@$) a) (a =. ({.n){y)) ({.n)} y else. x u y end. ) Maybe this answers your question about dyadic use: 1 + applyintree 1 <"0 i.2 3 ┌─┬─┬─┐ │0│1│2│ ├─┼─┼─┤ │4│5│6│ └─┴─┴─┘ 1 + (applyintree 1)"1 <"0 i.2 3 ┌─┬─┬─┐ │0│2│2│ ├─┼─┼─┤ │3│5│5│ └─┴─┴─┘ 1 2 + (applyintree 1)"1 <"0 i.2 3 ┌─┬───┬─┐ │0│2 3│2│ ├─┼───┼─┤ │3│5 6│5│ └─┴───┴─┘ 1 2 + (applyintree 1)"_1 <"0 i.2 3 ┌─┬─┬─┐ │0│2│2│ ├─┼─┼─┤ │3│6│5│ └─┴─┴─┘ 1 2 3 + (applyintree 1) <"0 i.2 3 ┌─┬─┬─┐ │0│1│2│ ├─┼─┼─┤ │4│6│8│ └─┴─┴─┘ 1 2&+ (applyintree 1) <"0 i.2 3 ┌───┬───┬───┐ │0 │1 │2 │ ├───┼───┼───┤ │4 5│5 6│6 7│ └───┴───┴───┘ - Original Message - From: Jose Mario Quintana To: Programming forum Cc: Sent: Friday, November 14, 2014 6:33 PM Subject: Re: [Jprogramming] Setting arbitrary leaf of tree This subject has been discussed many times in the forum; see, for example, http://www.jsoftware.com/pipermail/programming/2013-August/033228.html By the way, I am still wondering about the answer to my question in that message. -- 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] memory mapped files as non-volatile storage
Let's say I'd like to keep 5 data items as "permanent" accross program restarts. They change frequently. For example counters that are used as keys for next table records. Is keeping these counters in a memory mapped file, recommended? The nature of the counters is that they just need to never be reused, so they are incremented when read, and it is no big deal if there is a perfectly timed power outtage that doesn't cause the counter to be incremented, because that power outtage would also prevent the retrieved value from being used. It would also not be a major problem (though still not desirable) if the file became corrupted, because there is a procedure that can find the last counter (though it is more expensive than typical database apps of looking at the last record). What would be a major problem is if there is a lazyness to the writing of memory mapped files such that the retrieved counter value can be used without any guarantee that the file will be updated... that is if a power failure could occur 1 second or so after the memory mapped variable is updated, but the file would not be. If using memory mapped files this way is recommendable, is it best to used separate files for each (handful of) variable or a single file? -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Setting arbitrary leaf of tree
A version that is probably faster as it is not recursive, hook =: 2 : '([: u v) : (u v) ' amendT =: 2 : ' u hook (n { ]) n} ]' joinB =: 1 : ' ((- # m)&}.@;@(,&m&.>"1))'(@:(] :;)) uf2 =: 1 : ' '' each amendT '' joinB ": each ''[''; |. m ' uf =: 1 : '''x &'' , m uf2 ,'' y'''(4 :) (2;1;1)uf 4 : 'x &[ each amendT 1 each amendT 1 each amendT 2 y' 'Matt' (2;1;1)uf 'the cat';'sat';<'on';<('the';'mat') ┌───┬───┬───┐ │the cat│sat│┌──┬──┐│ │ │ ││on│┌───┬┐││ │ │ ││ ││the│Matt│││ │ │ ││ │└───┴┘││ │ │ │└──┴──┘│ └───┴───┴───┘ an applyintree version that returns a tacit verb, though dyads often result in rank errors eval =: 1 : ' a: 1 : m' ait =:(2 :' ('' each amendT '' joinB ": each u lrA ; |. n ) eval ') toupper ait (2;1;1) NB. returns long tacit verb toupper ait(2;1;1)'the cat';'sat';<'on';<('the';'mat') ┌───┬───┬──┐ │the cat│sat│┌──┬─┐│ │ │ ││on│┌───┬───┐││ │ │ ││ ││the│MAT│││ │ │ ││ │└───┴───┘││ │ │ │└──┴─┘│ └───┴───┴──┘ 'Fat' [ ait(2;1;1)'the cat';'sat';<'on';<('the';'mat') |rank error but these are ok: 'F' [ ait(2;1;1)'the cat';'sat';<'on';<('the';'mat') 'Fat'&, ait(2;1;1)'the cat';'sat';<'on';<('the';'mat') - Original Message - From: Jose Mario Quintana To: Programming forum Cc: Sent: Sunday, November 16, 2014 12:51 PM Subject: Re: [Jprogramming] Setting arbitrary leaf of tree Pascal wrote: > Maybe this answers your question about dyadic use: It is very helpful. My question was open-ended and you partially answered it; thanks a lot. I posed the question in the first place because Thomas and I have occasionally entertained the possibility of implementing, in a Jx interpreter, a version of }:: (even if it is only done for having a sense of completeness; a http://www.jsoftware.com/forumsearch for }:: returns 44 hits so far). Henry's applyintree conjunction could be a model for it but we do not fully understand it; see also Thomas's comment in the message http://www.jsoftware.com/pipermail/programming/2013-August/033229.html . I guess we will have to wait for Henry or someone else to update NuVoc as he suggested. There another reason to be cautious about the design; apparently }:: was (is?) meant to be an adverb, JVERSION Installer: j602a_win.exe Engine: j701/2011-01-10/11:25 Library: 6.02.023 a0=. }:: type'a0' ┌──┐ │adverb│ └──┘ On Fri, Nov 14, 2014 at 8:20 PM, 'Pascal Jasmin' via Programming < programm...@jsoftware.com> wrote: > that is a cool function. Similar to Raul's > > for those who had problems copying it: > > applyintree =: 2 : 0 > if. #n do. ((u applyintree (}.n)) L:_1 ({.n){y) ({.n)} y else. u y end. > : > NB. The rank is s,0 where s is the surplus of x-rank over y-rank. This > causes > NB. the cells of y to be matched up with the largest appropriate blocks > x. This > NB. is necessary because it is impossible to change the shape of the > values being modified > if. #n do. (x u applyintree (}.n) L:_ _1"(0 (,~ >.) x -&(#@$) a) (a =. > ({.n){y)) ({.n)} y > else. x u y end. > ) > > > Maybe this answers your question about dyadic use: > > 1 + applyintree 1 <"0 i.2 3 > ┌─┬─┬─┐ > │0│1│2│ > ├─┼─┼─┤ > │4│5│6│ > └─┴─┴─┘ > > > 1 + (applyintree 1)"1 <"0 i.2 3 > ┌─┬─┬─┐ > │0│2│2│ > ├─┼─┼─┤ > │3│5│5│ > └─┴─┴─┘ > > 1 2 + (applyintree 1)"1 <"0 i.2 3 > ┌─┬───┬─┐ > │0│2 3│2│ > ├─┼───┼─┤ > │3│5 6│5│ > └─┴───┴─┘ > > 1 2 + (applyintree 1)"_1 <"0 i.2 3 > ┌─┬─┬─┐ > │0│2│2│ > ├─┼─┼─┤ > │3│6│5│ > └─┴─┴─┘ > > > 1 2 3 + (applyintree 1) <"0 i.2 3 > ┌─┬─┬─┐ > │0│1│2│ > ├─┼─┼─┤ > │4│6│8│ > └─┴─┴─┘ > > > 1 2&+ (applyintree 1) <"0 i.2 3 > ┌───┬───┬───┐ > │0 │1 │2 │ > ├───┼───┼───┤ > │4 5│5 6│6 7│ > └───┴───┴───┘ > > > > > - Original Message - > From: Jose Mario Quintana > To: Programming forum > Cc: > Sent: Friday, November 14, 2014 6:33 PM > Subject: Re: [Jprogramming] Setting arbitrary leaf of tree > > This subject has been discussed many times in the forum; see, for example, > > http://www.jsoftware.com/pipermail/programming/2013-August/033228.html > > By the way, I am still wondering about the answer to my question in that > message. > > -- > 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] memory mapped files as non-volatile storage
there is FlushFileBuffers on windows (which is also available on mono), though I understand the real linux equivalent is fsync. It applies to OSX and android too. It can be expensive to call often, and the crossplatform behaviour can be iffy as some filesystems let the hard drive decide whether to really write the data, and other systems order the HD to flush (though the HD may still choose to take the order under advisement, and scores much better in benchmarks if it ignores the order) On the question of mapped files vs fwrite, a neat feature of mapped files is "atomicity on error" (no changes). A downside is that it takes 8KB even if your data is a few bytes. For application/data design, the question becomes is a transaction really complete (or does it really matter) if no one else knows about it? Rather than be paranoid about fsync and power failures, it is more important to have a recover operation from non-clean shutdown, and no matter how time consuming it is, use it if the cleanshutdown flag wasn't committed to disk. When thinking of a memory mapped file implementation, its a good idea to at least have a in memory with fread fwrite version as well, since for testing you are likely to often corrupt data, and fread/fwrite are needed for backups anyway. With that said, memory mapped files look interesting for fixed record number files (file growth doesn't need management), as its expected to be quick, and fewer special (fwrites) operations are needed. Does the memory mapped files lab exist on android? - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Sunday, November 16, 2014 12:11 PM Subject: Re: [Jprogramming] memory mapped files as non-volatile storage That depends on the OS. And, the disk itself. But J's practice of closing the file will flush it to disk. How long it takes though, for the operation to complete, depends on what else is happening (for the OS), and on details of the disk hardware (for the disk). And, of course, computers sometimes fail... And, occasionally, other bad things happen. You just have to make a best effort. Thanks, -- Raul On Sun, Nov 16, 2014 at 8:46 AM, Henry Rich wrote: > I think you'd have the power-fail problem with delayed writes even if you > use plain files. Writing to a file doesn't necessarily flush it to disk. > > Henry Rich > > On 11/16/2014 2:22 AM, Raul Miller wrote: > >> If your data is small, I'd just live with 1!:2 <'filename' >> >> Memory mapped files can be fun to work with, but I don't see any >> advantages for a situation like this. >> >> 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 -- For information about J forums see http://www.jsoftware.com/forums.htm
[Jprogramming] a weird thing with multiple : conjunction
as a test function Volume =: 3 : '''Volume is :'', (": l*w*h), '' for length '', (": l) , '' width '' , (": w) , '' and height '' , (": h) [''l w h'' =. y' Volume 3 4 5 Volume is :60 for length 3 width 4 and height 5 some functions for currying arbitrary parameters hook =: 2 : '([: u v) : (u v) ' itemamend =: 4 : '((2}.$y) $"1 0 x)} y' filtermodA =: 1 : 'u itemamend ] ,: (#inv~ u)' curry =: 4 : '(boxopen y) (a: = ]) filtermodA x' curryB=: 2 : 'u hook (n&curry)' This works: curry height to 4, and then in returned function, curry length to 3 Volume curryB ( a:, a:,<4) curryB (3;a:) ([: ([: Volume ((0$0);(0$0);4)&curry) :(Volume ((0$0);(0$0);4)&curry) (3;0$0)&curry) :(([: Volume ((0$0);(0$0);4)&curry) :(Volume ((0$0);(0$0);4)&curry) (3;0$0)&curry) calling with remaining parameter (width) 2 returns as desired Volume curryB ( a:, a:,<4) curryB (3;a:) 2 Volume is :24 for length 3 width 2 and height 4 it also works as a dyadic call Volume@:] curryB ( a:, a:,<4) curryB (3;a:) 2 Volume is :24 for length 3 width 2 and height 4 2 Volume@:] curryB ( a:, a:,<4) curryB (3;a:) 2 Volume is :24 for length 3 width 2 and height 4 If you look back to the returned function, it includes 3 : conjunctions to separate monad and dyad calls. I don't understand how multiple : works, and if you look closely, only the dyadic sides appear to be complete expressions that curry both the 4 and the 3 actually upon closer inspection of parentheses matching, at the top level, only the middle : exists. On a monadic call the left of that would be executed, but within that left side, only the right side of : provides the "right" answer. -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] a weird thing with multiple : conjunction
Thanks for your thoughts, Raul. Volume is a useless example function. the key part of the example function is that it takes 3 parameters with the 'l w h' =. y pattern. The other functions are generic meant to apply curry to any function that takes multiple parameters (through multi assign pattern). Including dyadic and ambivalent functions. even without a multi assignment function, you can still do: 1 1 1 + &> curryB ( a:, a:,<4) curryB (3;a:) 10 4 11 5 as a dyadic fork, this is also possible 3 (; curryB (1;2) + &> curryB ( a:, a:,<4) curryB (3;a:) ]) 10 6 11 6 (left tine (;) gets resolved as 3;1;2) In terms of currying the leftmost argument, that is easier, and as I understand the basics of Haskell, everything there is currying the left argument until there are no more arguments. Your approach to write a simple function that will place further arguments in order also works. Maybe that gets too complicated for 5+ parameters. curryB essentially does that, using a noun as the parameter template. The core of it is the verb rather than conjunction: (3;a:,a:,<4) curry 1;2 ┌─┬─┬─┬─┐ │3│1│2│4│ └─┴─┴─┴─┘ Your approach is more straightforward and efficient. My approach is more generic though. The big mystery to me though is how the compound : sentence manages to work despite a reading that it shouldn't. - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Monday, November 17, 2014 7:42 PM Subject: Re: [Jprogramming] a weird thing with multiple : conjunction I'm working through what you have done here, and am trying to understand your reasoning: Volume =: 3 : '''Volume is :'', (": l*w*h), '' for length '', (": l) , '' width '' , (": w) , '' and height '' , (": h) [''l w h'' =. y' This is a verb which only makes sense to use monadically. Also, it's mostly dealing with lists of characters, many of them quoted. I think I'd instead go with: Volume =: 3 : 0 volume=. ": */y 'l w h'=. ":&.> y 'Volume is ',volume,', for length ',l,', width ',w,' and height ',h ) The one-liner approach is great for experimenting, but not always so good for other people. (And, I have probably offended on the wrong side of that line, too often). Next, we have: hook =: 2 : '([: u v) : (u v) ' itemamend =: 4 : '((2}.$y) $"1 0 x)} y' filtermodA =: 1 : 'u itemamend ] ,: (#inv~ u)' curry =: 4 : '(boxopen y) (a: = ]) filtermodA x' curryB=: 2 : 'u hook (n&curry)' Studying this... the only left argument for 'hook' is Volume, which is monadic. So what this will achieve is needless duplication. Furthermore, what it's used for is not a hook but a hook-like concatenation mechanism. So what I think is needed here is a better name. Also, since the monadic/dyadic character of 'hook' is both irrelevant and distracting in this context, I think I'd go with a simpler definition. after=: 2 :'([ u v)' Or, actually after=: @: Or, actually, since at this point it's just a primitive, I'd not bother inventing another name for it. I am also tempted to use @ instead of @: because the right argument will always have infinite rank, but for this stage of this exercise I will refrain from that approach. itemamend =: 4 : '((2}.$y) $"1 0 x)} y' filtermodA =: 1 : 'u itemamend ] ,: (#inv~ u)' curry =: 4 : '(boxopen y) (a: = ]) filtermodA x' curryB=: 2 : 'u @: (n&curry)' And, with that change, the result of Volume curryB ( a:, a:,<4) curryB (3;a:) f. is somewhat readable. Looking at it, I expect that I should be able to do Volume curryB ( a:, a:,<4) curryB (3;a:) 5 but that gives me a domain error. So perhaps a different approach would be good? I guess what I think I would want is something which curries the leftmost or rightmost argument in a list. So I would want to generate Volume@(,&4)@(3&,) And, honestly, that is good enough as it is. However, if I wanted to get fancy, I could define curryR=: 2 :'u@(,&n)' curryL=: 2 :'u@(n&,)' Note that I am explicitly ignoring the possibility of a left argument for u. If I need a left argument, that's not an obstacle: I can curry ] and use that curried verb to provide the right argument of my dyadic verb. And I think that that approach is fine and good, if I am really trying to define useful modules. Of course, another approach would be to define something like: Volume@(3,],4:) But if I am going to go that route, I do not think that the abstract concept of "currying" adequately describes what I am doing. So I'd want to come up with a better name as m
Re: [Jprogramming] Boxing columns
Yes :P... a bit hard. allowed to use &. ? - Original Message - From: Henry Rich To: Programming forum Cc: Sent: Wednesday, November 19, 2014 5:08 PM Subject: Re: [Jprogramming] Boxing columns And I also meant, no use of @ . Henry Rich On 11/19/2014 5:05 PM, Henry Rich wrote: > boxcols i. 3 3 > +-+-+-+ > |0|1|2| > |3|4|5| > |6|7|8| > +-+-+-+ > > Can you write boxcols? > > Can you write it tacitly without using a hook, fork, compose, or appose? > > Henry Rich > -- > 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's wrong with assigment?
can use instead assign =: 4 : '(x) =: y' 'a' assign 2 you might like: assignwith 1 : 0 y assign u (y~ [ ]) :: ((i.0)"1) 1 : y assign x u (y~ [ ]) :: ((i.0)"1) 1 ) 5 +&^. assignwith 'a' 2.30259 a 2.30259 a =: @ ^. 5 |syntax error syntax error because adverb noun is not allowed, and that is parsed as (@^.) 5 - Original Message - From: Sergey Kamenev To: programm...@jsoftware.com Cc: Sent: Wednesday, November 19, 2014 5:03 PM Subject: [Jprogramming] What's wrong with assigment? a=:2 (a &+)\ 1 2 3 3 0 0 3 4 0 3 4 5 *(a & =:)\ 1 2 3* |syntax error | (a&=:)\1 2 3 *Why error?* Even more simple example a + & ^. 5 2.30259 a =: & ^. 5 |syntax error | a=:&^.5 *Why compose don't support assigment?* Sergey P.S. a =: @ ^. 5 |syntax error | a=:@^.5 -- 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] Boxing columns
tacit without fork/hook ,. each <"1&.|: i. 3 3 - Original Message - From: Henry Rich To: programm...@jsoftware.com Cc: Sent: Wednesday, November 19, 2014 5:23 PM Subject: Re: [Jprogramming] Boxing columns If you like... you don't need it. No @ or @: though. Henry Rich On 11/19/2014 5:21 PM, 'Pascal Jasmin' via Programming wrote: > Yes :P... a bit hard. allowed to use &. ? > > > - Original Message - > From: Henry Rich > To: Programming forum > Cc: > Sent: Wednesday, November 19, 2014 5:08 PM > Subject: Re: [Jprogramming] Boxing columns > > And I also meant, no use of @ . > > Henry Rich > > On 11/19/2014 5:05 PM, Henry Rich wrote: >> boxcols i. 3 3 >> +-+-+-+ >> |0|1|2| >> |3|4|5| >> |6|7|8| >> +-+-+-+ >> >> Can you write boxcols? >> >> Can you write it tacitly without using a hook, fork, compose, or appose? >> >> Henry Rich >> -- >> 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] Boxing columns
the 3rd is tacit and not a train. - Original Message - From: Marshall Lochbaum To: programm...@jsoftware.com Cc: Sent: Wednesday, November 19, 2014 10:29 PM Subject: Re: [Jprogramming] Boxing columns None of these beat Roger's by your criteria, but here are a few: (,,.)&.>/ i.3 3 <"_1|:,: i.3 3 (0 1,:3 1) <;.3 i.3 3 The second features a rare specimen--monadic |: on an array of rank greater than 2. Of course it looks a bit uglier when placed in tacit form. Marshall On Wed, Nov 19, 2014 at 05:05:16PM -0500, Henry Rich wrote: >boxcols i. 3 3 > +-+-+-+ > |0|1|2| > |3|4|5| > |6|7|8| > +-+-+-+ > > Can you write boxcols? > > Can you write it tacitly without using a hook, fork, compose, or appose? > > Henry Rich > -- > 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] Correct behavior of "e." ?
has to do with the definition of item 0 1 e. i. 2 2 1 1 3 e."0 1 i. 2 2 1 1 1 e."1 i. 2 2 1 0 - Original Message - From: Devon McCormick To: J-programming forum Cc: Sent: Thursday, November 20, 2014 1:19 PM Subject: [Jprogramming] Correct behavior of "e." ? Hi - I was just burned by this apparent anomaly: 1 e. 0~: i. 2 2 0 but 1 e. , 0~: i. 2 2 1 Has anyone else noticed this? Am I right in thinking this is incorrect behavior in the first case? Regards, Devon -- 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] Split on first found character
The spec (Fasta) can be revised to splitting on all LFs, where the first box is the control data, and subsequent boxes are the package. http://rosalind.info/glossary/fasta-format/ If so, you can grab all of the records from the sample link with this expression (copy records on clipboard, uses j8 clipboard access) cutLF each '>' cut wdclippaste '' The reason for the LFs in the payload as I understand it is to separate it into processing chunks. Having them boxed works for this, but if you ever need to put the LFs back, or join them into a single string LF joinstring ;/ 'abc' a b c '' joinstring ;/ 'abc' ; ;/ 'abc' NB. or this abc to extend Joe's solution (>@:{. ; ;@}.)@:cutLF each '>' cut - Original Message - From: Joe Bogner To: programm...@jsoftware.com Cc: Sent: Tuesday, November 25, 2014 6:00 AM Subject: Re: [Jprogramming] Split on first found character I might do it this way: (>@:{. ; ;@}.)@(LF&cut) x ┌───┬─┐ │case_id│GCTAGTCGACGTC│ └───┴─┘ On Tue, Nov 25, 2014 at 5:47 AM, Jan-Pieter Jacobs < janpieter.jac...@gmail.com> wrote: > I think I would solve it like this (with intermediate steps): > > x=: 'case_id', LF, 'GCTAGTCG', LF, 'ACGTC', LF > > NB. Find the locations of LF's in the string > (LF = ]) x > > NB. assign 0 to everything before the LF, assign 1 to everything after it > ([: +./\ LF = ]) x > > NB. The wonderful "key" adverb lets you apply verbs based on it's key > (another array), eg. box > ( > NB. Get rid of the LF's by replacing < by a version removing LF: > ((<@#~ LF~:])/.~ [: +./\ LF = ]) x > > This is what I came up with, but smarter people will probably suggest more > elegant ways. > > I hope this is useful. > Jan-Pieter > > 2014-11-25 11:00 GMT+01:00 Ryan : > > > I have a character array with LF's, and want to split it on the > > first LF, and remove the remaining LF's. I'm wondering if there's a > > simpler > > way than what I'm doing now: > > > > x=: 'case_id', LF, 'GCTAGTCG', LF, 'ACGTC', LF > > > > filterLF=: #~ ~:&LF > > headLF=: {.~ i.&LF > > tailLF=: }.~ i.&LF > > (headLF ; filterLF@tailLF) x > > ┌┬─┐ > > │>case_id│GCTAGTCGACGTC│ > > └┴─┘ > > > > (I'm reading text files in fasta format: http://rosalind.info/glossary/ > > fasta-format/) > > > > Thanks for any suggestions, > > Ryan > > > > > > > > The information in this e-mail is intended only for the person to whom it > > is > > addressed. If you believe this e-mail was sent to you in error and the > > e-mail > > contains patient information, please contact the Partners Compliance > > HelpLine at > > http://www.partners.org/complianceline . If the e-mail was sent to you > in > > error > > but does not contain patient information, please contact the sender and > > properly > > dispose of the e-mail. > > -- > > 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] Get unique results each time you use deal and roll
9!:45 will set the seed. J on startup has the same seed. For the default generator, 9!:45 will take a long array as the seed (basically a polynomial representation of a 19000 bit number) If you use the first random number generator (gbflip), the seed is a 31bit number. I've posted ways to get portable 32/64 bit compatible streams from that generator, but the others are not consistent between 32 and 64 bit platforms. You can probably use time as a seed with default generator if you cut off the miliseconds. - Original Message - From: Linda Alvord To: programm...@jsoftware.com Cc: Sent: Friday, November 28, 2014 8:01 PM Subject: [Jprogramming] Get unique results each time you use deal and roll 7?7 1 4 5 0 6 2 3 10?10 5 1 3 2 4 0 7 8 6 9 Now run the code again after closing J and you get the same results. How can you get different results each time. I vaguely rember using some date or other number with roll to insure different results. 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] Emscripted J
the interop functionality isn't quite exposed in the UI, but typing the following in the "J window" will draw to canvas 'drawRect' (15!:0) (10,10,10,10) - Original Message - From: Joe Bogner To: programm...@jsoftware.com Cc: Sent: Saturday, November 29, 2014 1:47 PM Subject: Re: [Jprogramming] Emscripted J Hi greg, Yes, see https://joebo.github.com/j-emscripten/full.html and the interop examples I hacked jtforeign to execute a different function on 15!:0 which can be overridden in javascript: https://github.com/joebo/j-emscripten/blob/master/full.html#L317 I can probably undo the hack and go back to using stock jtforeign Interacting with the DOM/javascript can be seen with the alert or canvas examples There's some oddities still with passing arrays. An array that looks boolean [0,1,1] seems to be stored differently than regular numeric array [2,3,4] I can't say that I have it all figured out yet, but enough for a proof of concept. I can pass strings and numeric arrays that don't contain 0,1 On Sat, Nov 29, 2014 at 1:35 PM, greg heil wrote: > Joe > > >Lovely! Have you found anyway for this Javascripted j to communicate with > the DOM though. Or even a way to sift from a javascript array to a (boxed) > J array? > > greg > ~krsnadas.org > > -- > > from: Joe Bogner > to: programm...@jsoftware.com > date: 29 November 2014 at 10:09 > subject: Re: [Jprogramming] Emscripted J > > Hi Devon, > > Yes, exactly. > > See: http://jsoftware.com/pipermail/chat/2014-November/006332.html > > >Here's is a extremely minimal example with jsFiddle > http://jsfiddle.net/50Lf2m6v/1/ . The only dependency is the > j-called.min.js file > > >You can see a trimmed down version version of the generated script here: > https://github.com/joebo/j-emscripten/blob/master/j-called.js . Minified > it is about 1MB > > -- > > from: Devon McCormick > to: J-programming forum > date: 29 November 2014 at 09:34 > subject: [Jprogramming] Emscripted J > > Hi - > > >to be clear, does having this emscripted, Javascript version of J mean I > should be able to run J code on a client-side web page by including the > Javascript module? > > --- > 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] Hexadecimal conversion
In J8, there are profile entries: hfd and dfh. Its available in addons for earlier versions. hfd 15 17 0f 11 hfd 15 f - Original Message - From: Jon Hough To: "programm...@jsoftware.com" Cc: Sent: Monday, December 1, 2014 10:24 AM Subject: [Jprogramming] Hexadecimal conversion I have been trying to understand the hex conversion 3!:3 (see : http://www.jsoftware.com/docs/help701/dictionary/dx003.htm ) but cannot understand what the result is. If I define tohex =: 3!:3 and I want to choose to represent my integer in standard byte order hex, I can do: 0 tohex 15 which gives, e000 0004 0001 000f It seems what I want is in the last row (000f = 15). But what does all the rest mean? 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] Modifying x inside Infix
The argument to 4 u\ y will be entirely y, and u is monadic. you can do something like this though: 2 (3&+)\ i.5 3 4 4 5 5 6 6 7 If you can change your spec to "updating y" on every iteration, and you want to apply to: x1 u (x2 u y) then you can make a table where x1, x2 and y are the 3 rows, and then call with u/. You can search for boxscan in archives for method where x and y are not the same shape. This is generally preferable to trying to keep a side effect between calls (so you don't need to worry about initializing it) From: Jon Hough To: "programm...@jsoftware.com" Sent: Tuesday, December 2, 2014 7:58 PM Subject: [Jprogramming] Modifying x inside Infix If y is a list and I have a dyadic verb u, which I want to apply to every 4 items of y I can do x ( 4 u \) y and this will apply x u to every 4 items. But I want to continually update x every iteration. So after doing x u y to the first 4 items, x becomes the result, i.e. x =: x u y How do I do this for all the list? I tried things like result =: leftArg ( 4 (leftArg =:) u \ )rightArg but I can't get the correct syntax (assuming there is a way to do this). (I hope my explanation made sense.) 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] Modifying x inside Infix
If you use your x as y, and y as x, then one argument has length 4 while the other length 1, and producing a length 1 result, then it fits the requirement for boxscan. boxscan =: ((&.>)/)(>@:) 1 (, <)~ |. <"1 i.4 4 ┌───┬─┬───┬───┬─┐ │12 13 14 15│8 9 10 11│4 5 6 7│0 1 2 3│1│ └───┴─┴───┴───┴─┘ +/@:+ boxscan 1 (, <)~ {: |. <"1 i.4 4 10 +/@:+ boxscan 1 (, <)~ |. <"1 i.4 4 1198 - Original Message - From: Jon Hough To: "programm...@jsoftware.com" Cc: Sent: Tuesday, December 2, 2014 9:09 PM Subject: Re: [Jprogramming] Modifying x inside Infix I do not think updating y is what I need in this case.In pseudocode, an example is x = 3; //just some start value for xy; //some arrayfor (i = 0; i < max; i+= 4){ x = myVerb(x, y[i], y[i+1], y[i+2], y[i+3]); //my verb is equivalent(~ish) to verb u.} return x; So I thought using u\ would be a good way to do the forloop. The problem, of course, is that the previous iteration's result of myVerb is the next iterations myVerb parameter. I'm not wedded to the idea of using u\, and I am beginning to wonder if it is completely inappropriate for doing this. > Date: Wed, 3 Dec 2014 01:27:39 + > From: programm...@jsoftware.com > To: programm...@jsoftware.com > Subject: Re: [Jprogramming] Modifying x inside Infix > > The argument to 4 u\ y will be entirely y, and u is monadic. > > you can do something like this though: > > 2 (3&+)\ i.5 > 3 4 > 4 5 > 5 6 > 6 7 > > > If you can change your spec to "updating y" on every iteration, and you want > to apply to: > > x1 u (x2 u y) > then you can make a table where x1, x2 and y are the 3 rows, and then call > with u/. You can search for boxscan in archives for method where x and y are > not the same shape. This is generally preferable to trying to keep a side > effect between calls (so you don't need to worry about initializing it) > > > > From: Jon Hough > To: "programm...@jsoftware.com" > Sent: Tuesday, December 2, 2014 7:58 PM > Subject: [Jprogramming] Modifying x inside Infix > > > If y is a list and I have a dyadic verb u, which I want to apply to every 4 > items of y I can do > > x ( 4 u \) y > > > and this will apply x u to every 4 items. > > > But I want to continually update x every iteration. So after doing x u y to > the first 4 items, x becomes the result, > > > i.e. x =: x u y > > > How do I do this for all the list? > > > I tried things like > result =: leftArg ( 4 (leftArg =:) u \ )rightArg > > > but I can't get the correct syntax (assuming there is a way to do this). > (I hope my explanation made sense.) > 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 -- 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] Pad Arrays for XORing
,: will pad whatever side is shortest (i.5) ,: i.3 0 1 2 3 4 0 1 2 0 0 for xor (i.5) (22 b.)/@:,: i.3 0 0 0 3 4 - Original Message - From: Jon Hough To: "programm...@jsoftware.com" Cc: Sent: Wednesday, December 3, 2014 7:56 PM Subject: [Jprogramming] Pad Arrays for XORing If I want to XOR two arrays (~:), I run into a problem if the two arrays are of different length. So before XORing I use my "pad" dyadic verb which pads zeros onto the front of the right argument (which is assumed to be the shorter array). pad =: ((#&0)@:(([: # [) - ([: # ]))) , ] I imagine this problem is common, so is there a standard verb to do this? I think my verb is not the most elegant, and it has the deficiency of assuming the right argument is the shorter. -- 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] Pad Arrays for XORing
if xoring bits, yes. When the word pad comes up in the same sentence, I thought you might want to xor bytes. - Original Message - From: Jon Hough To: "programm...@jsoftware.com" Cc: Sent: Wednesday, December 3, 2014 8:19 PM Subject: Re: [Jprogramming] Pad Arrays for XORing Should I not use ~: for XORing? e.g. if a =: 1 0 1 1 1 1 1and b =: 0 1 0 1 1 > Date: Thu, 4 Dec 2014 01:11:05 + > From: programm...@jsoftware.com > To: programm...@jsoftware.com > Subject: Re: [Jprogramming] Pad Arrays for XORing > > ,: will pad whatever side is shortest > > (i.5) ,: i.3 > 0 1 2 3 4 > 0 1 2 0 0 > > > for xor > > (i.5) (22 b.)/@:,: i.3 > 0 0 0 3 4 > > > - Original Message - > From: Jon Hough > To: "programm...@jsoftware.com" > Cc: > Sent: Wednesday, December 3, 2014 7:56 PM > Subject: [Jprogramming] Pad Arrays for XORing > > If I want to XOR two arrays (~:), I run into a problem if the two arrays are > of different length. > So before XORing I use my "pad" dyadic verb which pads zeros onto the front > of the right argument (which is assumed to be the shorter array). > > pad =: ((#&0)@:(([: # [) - ([: # ]))) , ] > > > I imagine this problem is common, so is there a standard verb to do this? I > think my verb is not the most elegant, and it has the deficiency of assuming > the right argument is the shorter. > > -- > 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] J and data analysis/relational algebra
select where u is (] #~ u) fromthis joins can be a bit tricky (though as Chris mentioned you can consider jd or jdb). You can also look up inverted tables on wiki. Some extra options in J when working with data is to separate your tables by data type so that you have a lot of 1 to 1 relationships, but text and numbers are in different variables/files so that you can avoid boxing. This is the main motivations behind column databases such as JD, but grouping columns by datatype can have some related J efficiencies. sql one-to-many joins produce tables where the rows from the one side get repeated for each of the many side. An alternative that existed before sql is to look up stuff in one table based on another table. That can often be done in one short line in J, and potentially is more optimized (based on knowlege of where you should look first) than sql. Another join alternative available in J is to box the many side records into a single cell and so avoid data repetition from the one side of the join. With boxes in J, you can store variable lists, lists of lists, or trees of lists of tree lists into a single cell, so J can combine relational and document structures. group by functionality can often be accomplished with key /. From: Ryan To: Programming forum Sent: Sunday, December 7, 2014 9:57 PM Subject: [Jprogramming] J and data analysis/relational algebra I appreciate how helpful this forum has been so far so I'd thought I'd ask another question. Essentially, can someone point me to how J users perform the basic data manipulation operations that you can do, for example, using R's dplyr or SQL queries? Specifically, I want to be able to (mainly on a bunch of csv files): Do unions, joins, selects, filters, group by's, and create new columns as functions of other columns. I want to get a sense of how easy it is compared to R, and hopefully learn efficient ways of doing it in J. thanks for any help, Ryan The information in this e-mail is intended only for the person to whom it is addressed. If you believe this e-mail was sent to you in error and the e-mail contains patient information, please contact the Partners Compliance HelpLine at http://www.partners.org/complianceline . If the e-mail was sent to you in error but does not contain patient information, please contact the sender and properly dispose of the e-mail. -- 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 neat OOP trick with adverbs
adverbs can return nouns, though most are designed to return a verb. 1 : 'm + y' NB. a verb because it accesses y 1 : 'u 2' NB. returns a noun because it doesn't access y even though it uses a verb as adverb parameter Consider this noun producing adverb, A_z_ =: 1 : 'a =: u a' its defined in z, just for convenience. It applies its verb parameter to a and stores the result in a. The value of a it will use is whatever locale it is qualified with. a=.1 a_b_ =: 3 +: A 2 +: A_b_ 6 a_b_ 6 a&+ A_b_ NB. the a parameter is taken from caller's locale as u is parsed before it is passed to A_b_ 8 a_b_ =: i.5 a&(0}) A_b_ NB. sending parameters to amend in place 2 1 2 3 4 OOP approach often involves creating side effects in class instances. Noun returning adverbs can access all instance variables (or other program data), and make any side effects it wants. For instance, it can save or backup data to disk in the last amend example. The neat part is that with class defined adverbs, you can send verb messages to your objects. Even though they are verbs, they can be bound with many caller supplied nouns (such as the 2 parameters to }), and in a tacit expression caller variables get fixed into the supplied verb. Its also neat, because many other uses of adverbs in objects are unintuitively problematic in their parsing. -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] A neat OOP trick with adverbs
Placing this in a file and then loading coclass 'myclass' a =: 2 NB. member variable inside class or object. Noun intended. A =: 1 : ' a=: u a' NB. adverb that will modify member variable in console (base locale) you can do: a =. conew 'myclass' NB. a is variable in base locale +: A__a 4 3&+ A__a 7 a__a7 +: A_myclass_ NB. uses class variable instead of instance variable. future conew's would use 4 as the initial instance val 4 In terms of what you were trying to do, =. is always local to the function =: keeps variables within a locale. I'm not completely sure why top level (console) allows =., but I suspect it is just an added debugging convenience. The intended benefit of the adverb pattern is allowing your code to receive variable verbs/functions to apply to the current state of your object, and likely to modify its state. Amending an internal table for example. But another example would be moving the x/y coordinates of a game/visual object 2 3"_ A__a 2 3 2 3&+ A__a [ 2 3"_ A__a 4 6 I'm passing a move order that is relative to the existing state. While there is always the alternative of this longer expression: a__a =: 2 3 + a__a the big advantage of the adverb approach is that you can extend the adverb to not just make the move, but also check for collisions, send a rendering command, or perhaps generate a more complex timelapse of the movement from the old and destination states, and those features can be added in 2.0/3.0 iterations without affecting all of the "client"/consumer code that just cares about moving tiles around. - Original Message - From: Jon Hough To: "programm...@jsoftware.com" Cc: Sent: Tuesday, December 9, 2014 11:15 AM Subject: Re: [Jprogramming] A neat OOP trick with adverbs I was playing with your adverbs.Any idea why the following doesn't work? coclass 'myclass'empty =: ''classname =: myclass A_myclass_=:1 :'a =. empty&u classname' conew A error is: I get the following error: |value error: create__w | create__w x My intention was to instantiate 'a' as an instance of myclass (but also keeping it private for whatever reason). > Date: Tue, 9 Dec 2014 03:31:23 + > From: programm...@jsoftware.com > To: programm...@jsoftware.com > Subject: [Jprogramming] A neat OOP trick with adverbs > > adverbs can return nouns, though most are designed to return a verb. > > 1 : 'm + y' NB. a verb because it accesses y > 1 : 'u 2' NB. returns a noun because it doesn't access y even though it uses > a verb as adverb parameter > > Consider this noun producing adverb, > A_z_ =: 1 : 'a =: u a' > > its defined in z, just for convenience. It applies its verb parameter to a > and stores the result in a. The value of a it will use is whatever locale it > is qualified with. > > a=.1 > a_b_ =: 3 > > +: A > 2 > > +: A_b_ > 6 > a_b_ > 6 > > a&+ A_b_ NB. the a parameter is taken from caller's locale as u is parsed > before it is passed to A_b_ > 8 > > > a_b_ =: i.5 > a&(0}) A_b_ NB. sending parameters to amend in place > 2 1 2 3 4 > > > OOP approach often involves creating side effects in class instances. Noun > returning adverbs can access all instance variables (or other program data), > and make any side effects it wants. For instance, it can save or backup data > to disk in the last amend example. > > The neat part is that with class defined adverbs, you can send verb messages > to your objects. Even though they are verbs, they can be bound with many > caller supplied nouns (such as the 2 parameters to }), and in a tacit > expression caller variables get fixed into the supplied verb. Its also neat, > because many other uses of adverbs in objects are unintuitively problematic > in their parsing. > -- > 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] Calling Command line tools from J
the jtask locale is loaded by default. launch fork and spawn are the main functions. From: Jon Hough To: "programm...@jsoftware.com" Sent: Sunday, December 14, 2014 1:26 AM Subject: [Jprogramming] Calling Command line tools from J If I want to call a command line tool, e.g. openssl, how can I do this from JQT? Is it possible? I'm thinking of something similar to Python's os.system https://docs.python.org/2/library/os.html#os.system -- 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] "Such that" syntax in J
It seems that "such that" is indistinguishable (to me) with select. While I do not use a "select" utility adverb (I write out a # expression each time), making these utility adverbs is a great step in learning J, and making the language fit the concepts you already understand in your mind. With that said, my ideal definition of select is: select =: 1 : 'u # ]' The big difference with yours is that u can be a dyadic verb. 1000 (< *:) select i.50 From: Jon Hough To: "programm...@jsoftware.com" Sent: Friday, December 26, 2014 12:07 PM Subject: Re: [Jprogramming] "Such that" syntax in J Another example suchthat =: adverb define (#~u) y ) Find all positive int x less than 100 such that x^2 > 1000 ((1000&<)@:*:) suchthat i. 100 This seems to be what I wanted. Come to think of it, since the expression is {x | x < 100 AND x^2 > 1000} the i. 100 part should belong on the left side since it is part of the "such that" condition. > Date: Fri, 26 Dec 2014 09:00:15 -0800 > From: rogerhui.can...@gmail.com > To: programm...@jsoftware.com > Subject: Re: [Jprogramming] "Such that" syntax in J > > Using -: in that context requires extra parens. Besides, ←→ is prettier. > > On Fri, Dec 26, 2014 at 8:52 AM, R.E. Boss wrote: > > > > Why not use the primitive '-:' ? > > > > (+/(1+i._)^-s) -: */%1-(p:i._)^-s > > > > > > R.E. Boss > > > > > > > -Original Message- > > > From: programming-boun...@forums.jsoftware.com [mailto:programming- > > > boun...@forums.jsoftware.com] On Behalf Of Roger Hui > > > Sent: vrijdag 26 december 2014 17:28 > > > To: Programming forum > > > Subject: Re: [Jprogramming] "Such that" syntax in J > > > > > > ←→ are metasymbols, commonly used in mathematics to denote > > > equivalence. > > > > > > > > > > > > On Fri, Dec 26, 2014 at 8:20 AM, Jon Hough wrote: > > > > > > > > Thanks for replying. > > > > > > > > I'm confused about two things. > > > > > > > > (1) I'm worried I haven't explained myself well. > > > > I mean I want to find all x given g(x) is true for some function g. > > > > > > > > i.e. the set { x | g(x) is true } > > > > (You may have answered this, I need to read your example more > > carefully, > > > > but this leads me to problem 2...) > > > > > > > > (2) I don't understand what > > > > ←→ > > > > means in terms of J. These are not ASCII characters or J primitives. > > > > > > > > Thanks. > > > > > > > > > Date: Fri, 26 Dec 2014 08:13:40 -0800 > > > > > From: rogerhui.can...@gmail.com > > > > > To: programm...@jsoftware.com > > > > > Subject: Re: [Jprogramming] "Such that" syntax in J > > > > > > > > > > f x > > > > > > > > > > where x is an array of all values of interest. For (countably) > > infinite > > > > > sets you have to express x in terms of i._ . For example, to > > express the > > > > > Euler product formula for the Riemann zeta function, > > > > > > > > > >+/(1+i._)^-s ←→ */%1-(p:i._)^-s > > > > > > > > > > > > > > > > > > > > On Fri, Dec 26, 2014 at 8:04 AM, Jon Hough > > > wrote: > > > > > > > > > > > > In Haskell (and other languages I'm sure) one can express the idea > > of > > > > > > "such that" to denote one expression depending on another. In > > Haskell > > > > we > > > > > > can use the syntax: > > > > > > > > > > > > [ f x | x <- xs ] > > > > > > > > > > > > which means > > > > > > "the list of all f x > > > > > > such that x is drawn from xs." > > > > > > > > > > > > So | is syntactically similar to the English "such that". (and very > > > > much > > > > > > like | in mathematical sets) > > > > > > > > > > > > I would like to know if J has a construct to express the above > > Haskell > > > > > > code. > > > > > > > > > > > > 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 > > > > > > > > -- > > > > 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
[Jprogramming] variable integer coding (challenge)
A common design decision is how large to make a field. For many numbers, we think that a byte will be large enough to hold practical values, but one day we will find out that it is not. This is essentially the Y2k problem, or year 2032 issue. A simple variable integer coding (tied to byte ranges) toVint =: [: ; (255&| ,~ 255 #~ <.@%&255) each toVint 566 44 255 255 56 44 It now takes 3 bytes to store 566, and one byte to store 44. the challenge is to write fromVint such that 566 44 -: fromVint 255 255 56 44 as an extra challenge, is there a way to write toVint or fromVint such that it is faster than using intermediate boxing? -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] variable integer coding (challenge)
Nice Raul, thank you. Your toVint is 10x faster than mine. my less pretty fromVint fromVbyte=: [: +/&> (255 &>) (<;.2) ] The neat part of the challenge is seeing how dyadic ;. is frequently an elegant alternative to "I might need a loop for this" Your use of #: to make records (rows) is quite cool too. I also didn't know that u&, could combine operations on rows into a list. - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Monday, December 29, 2014 12:44 PM Subject: Re: [Jprogramming] variable integer coding (challenge) Here's a faster version of toVint, for at least some right arguments: toVint2=: [: (({."1 ,. 1:) #&, 255 ,. {:"1) 0 255 #: ] Here's an implementation of fromVint: fromVint=: 255&~: +/;.2 ] Thanks, -- Raul On Mon, Dec 29, 2014 at 12:12 PM, 'Pascal Jasmin' via Programming wrote: > A common design decision is how large to make a field. For many numbers, we > think that a byte will be large enough to hold practical values, but one day > we will find out that it is not. This is essentially the Y2k problem, or > year 2032 issue. > > A simple variable integer coding (tied to byte ranges) > > toVint =: [: ; (255&| ,~ 255 #~ <.@%&255) each > > toVint 566 44 > 255 255 56 44 > > It now takes 3 bytes to store 566, and one byte to store 44. > > the challenge is to write fromVint such that > > > 566 44 -: fromVint 255 255 56 44 > > as an extra challenge, is there a way to write toVint or fromVint such that > it is faster than using intermediate boxing? > -- > 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 at 3:10 PM, Raul Miller < >> <mailto:rauldmil...@gmail.com> rauldmil...@gmail.com> >> >> > 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@[))^:( >> <mailto:0=6&;|@%7b:@%7b.)%5e:_~> 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 < >> >> > > <mailto:programm...@jsoftware.com> programm...@jsoftware.com> wrote: >> >> > > >> >> > >> this works >> >> > >> >> >> > >> (, >:@?@6:)^:((0=#) +. 6={:)^:_ i.0 >> >> > >> >> >> > >>([: +/ (, >:@?@6:)^:((0=#) +. 6={:)^:_) i.0 >> >> > >> 11 >> >> > >> >> >> > >> >> >> > >> >> >> > >> - Original Message - >> >> > >> From: Johann Hibschman < <mailto:jhibsch...@gmail.com> >> jhibsch...@gmail.com> >> >> > >> To: Programming forum < <mailto:programm...@jsoftware.com> >> programm...@jsoftware.com> >> >> > >> 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> >> http://www.jsoftware.com/forums.htm >> >> > >> >> >> > >> --- >> >> > >> --- For information about J forums see >> >> > >> <http://www.jsoftware.com/forums.htm> >> http://www.jsoftware.com/forums.htm >> >> > >> >> >> > > >> >> > > -- For information about J forums see >> >> > > <http://www.jsoftware.com/forums.htm> >> http://www.jsoftware.com/forums.htm >> >> > -- >> >> > For information about J forums see < >> http://www.jsoftware.com/forums.htm> >> http://www.jsoftware.com/forums.htm >> >> > >> >> -- >> >> For information about J forums see <http://www.jsoftware.com/forums.htm> >> 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] variable integer coding (challenge)
Here is a useful set of utilities for working with variable length strings/lists packed in a variable (or row) without boxes. One reason to do such packing is that strings take much less memory than other lists , and much less memory than boxes, together with faster general operations. The context implies medium sized strings where most are under 255 bytes long, and those that are more are not much more (A mailing address for example) toVbyte =: [: (({."1 ,. 1:) #&, 255 ,. {:"1) 0 255 #: ] fromVbyte=: 255&~: +/;.2 ] fromSomeVbyte =: [ (;@:}. ;~ [ {. +/&>@:]) 255&~:@:] <;.2 ] NB. x is number of Vbytes to take. Result is unpacked NB. nums and remainder list. toVint =: 1 : '[: (({."1 ,. 1:) #&, m ,. {:"1) (0, m) #: ]' fromVint=: 1 : 'm&~: +/;.2 ]' toVstring =: toVbyte@:# , a.&i. toVstrings =: [: ; toVstring each NB. places list as length string length string fromVstring =: 1&unpackStrings fromAllstrings =: [: ([: }.@:}: {."1) [: fromVstring@:( >@:{:)^:(a:) < packStrings =: [: (([: ; {:"1) ,~ [: toVbyte@:> {."1 ) 1 fromSomeVbyte &> toVstring each NB. places all lengths NB.at head, then packed list after. unpackStrings =: [: _2&}. ([ (_2&}. , (({.@:[ }. ]) (, <)~ }.@:[ ;~ {.@:[ {. ])&>/@:(_2&{.))@:]^:[ fromSomeVbyte) There are 2 ways to pack strings depending on whether there is a fixed number of them, or an unknown number. toVstrings 'abc';'defg'; 257 $ 'ghj' 3 97 98 99 4 100 101 102 103 255 2 103 104 106 103... to get originals... a.&{ each fromAllstrings toVstrings 'abc';'defg'; 257 $ 'ghj' The version that places all lengths at head: packStrings 'abc';'defg'; 257 $ 'ghj' 3 4 255 2 97 98 99 100 101 102 103 103 104 106 ... You can obtain just the lengths: > {. 3 fromSomeVbyte packStrings 'abc';'defg'; 257 $ 'ghj' 3 4 257 fromSomeVbyte returns 2 boxes: the first x numbers followed by the remainder of the list. you can obtain the unpacked strings if you know how many there are. {&a. each 2{. 3 unpackStrings packStrings 'abc';'defg'; 257 $ 'ghj' ┌───┬┐ │abc│defg│ └───┴┘ You can make mixed integer and string packing pretty easily: (put all non strings/lists first) ] packing =: (toVbyte 344 622 11) , packStrings 'abc';'defg';'hj' 255 89 255 255 112 11 3 4 2 97 98 99 100 101 102 103 104 106 ' ] 'ints strs' =: 3 fromSomeVbyte packing ┌──┬──┐ │344 622 11│3 4 2 97 98 99 100 101 102 103 104 106│ └──┴──┘ {&a. each _2}. 3 unpackStrings strs ┌───┬┬──┐ │abc│defg│hj│ └───┴┴──┘ - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Monday, December 29, 2014 12:44 PM Subject: Re: [Jprogramming] variable integer coding (challenge) Here's a faster version of toVint, for at least some right arguments: toVint2=: [: (({."1 ,. 1:) #&, 255 ,. {:"1) 0 255 #: ] Here's an implementation of fromVint: fromVint=: 255&~: +/;.2 ] Thanks, -- Raul On Mon, Dec 29, 2014 at 12:12 PM, 'Pascal Jasmin' via Programming wrote: > A common design decision is how large to make a field. For many numbers, we > think that a byte will be large enough to hold practical values, but one day > we will find out that it is not. This is essentially the Y2k problem, or > year 2032 issue. > > A simple variable integer coding (tied to byte ranges) > > toVint =: [: ; (255&| ,~ 255 #~ <.@%&255) each > > toVint 566 44 > 255 255 56 44 > > It now takes 3 bytes to store 566, and one byte to store 44. > > the challenge is to write fromVint such that > > > 566 44 -: fromVint 255 255 56 44 > > as an extra challenge, is there a way to write toVint or fromVint such that > it is faster than using intermediate boxing? > -- > 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] variable integer coding (challenge)
I also provided some adverbs toVint =: 1 : '[: (({."1 ,. 1:) #&, m ,. {:"1) (0, m) #: ]' fromVint=: 1 : 'm&~: +/;.2 ]' these let you set the breakup point to what you wish 15 toVint 33 12 17 15 15 3 12 15 2 511 toVint 1233 511 511 211 511 fromVint 511 toVint 1233 444 1233 444 It can provide simple compression. If you have a list of many strings where almost all of them will fit into a 6bit alphabet, you can still encode a full 7 bit or 8bit alphabet. On average, you'd save space using 6bit alphabet, depending on your context. The variable string functions I showed, still let you do a substring search on the packed data. Part of it is disk and memory compression (don't expand until you need to, and a string takes much less memory than a list of numbers < 256), but part of it is not being forced in design to determine what the impossible cutoff number is. A big advantage related to J is having binary data records. If you encode the length of the binary data, you no longer have to box them if a trailing 0 or space would be difficult to know whether it is a fill or intentional. Beyond binary data, there is dumb stuff such as storing addresses. Most people have just 1, Most fit within 255 bytes. Usually no one cares about address info except when they do or already have the client record. Do you really want a separate table with 1 to many join with a possible 1 character fixed size per address just because you're unsure if it will ever be possible for you to store an address to an African village as a set of driving instructions and then a description of the house relative to 3 other houses and landmarks just in case one of the other houses gets painted. Another neat feature about the coding method is that if you have a lot of inefficient codes, ie. storing 1020 as 255 255 255 255 0, it at least compresses well. A minor thing is that the encoding still lets you do search by < or >. If you are storing the number of orders per customer. The first byte tells you whether it is > 254 or less than any other number below 255 (probably enough info to select customers of interest). Another minor thing is that you don't have to use the encoding codes until there is an overflow. It may be easier to just switch functions to decode variable data, then to reshape terrabytes of data. From: Joe Bogner To: programm...@jsoftware.com Sent: Tuesday, December 30, 2014 10:45 AM Subject: Re: [Jprogramming] variable integer coding (challenge) Pascal, Thanks for sharing. Can you also share a potential use case? I had to remind myself about the size of integers (4 bytes) on 32-bit. Will this only save space on numbers less than 1019? NB. 4 bytes toVint2 1019 255 255 255 254 NB. 5 bytes toVint2 1020 255 255 255 255 0 Are you looking for the savings in terms of disk space (saving it to a file) or working memory? On Mon, Dec 29, 2014 at 12:12 PM, 'Pascal Jasmin' via Programming wrote: > A common design decision is how large to make a field. For many numbers, we > think that a byte will be large enough to hold practical values, but one day > we will find out that it is not. This is essentially the Y2k problem, or > year 2032 issue. > > A simple variable integer coding (tied to byte ranges) > > toVint =: [: ; (255&| ,~ 255 #~ <.@%&255) each > > toVint 566 44 > 255 255 56 44 > > It now takes 3 bytes to store 566, and one byte to store 44. > > the challenge is to write fromVint such that > > > 566 44 -: fromVint 255 255 56 44 > > as an extra challenge, is there a way to write toVint or fromVint such that > it is faster than using intermediate boxing? > -- > 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] variable integer coding (challenge)
I was not thinking of encoding a whole table, into a binary field, but that could be done as you described too. My specific use case is storing 2 public cryptographic keys per user, along with a version number that indicates key size and algorithm involved. That version number is almost surely going to stay below 256 (maybe under 16 for a long time), but its not impossible that it grows. The keys are most naturally large extended numbers, but a byte representation is also natural. This is part of an inverted table record structure. Because the version numbers are small, and the extended numbers large, it would make sense that they are each in their own inverted table box for space reasons A reasonable alternative would be to have a list of 2 integers for the version number 3 : '7!:5 < ''y''' 1 2 $ i.256 262144 3 : '7!:5 < ''y''' 1 2 $ {&a. i.256 32768 for 10k records, encoding 2 extended numbers 200 to 300 bits long as strings, save 4.5MB. A 5x ratio stays for larger bit sizes too. 3 : '7!:5 < ''y''' {&a. 256 #.inv 2x ^ 100 + ?. 1 2 $ 200 5.56723e6 3 : '7!:5 < ''y''' {&a. 256 #.inv 2x ^ 100 + ?. 1 2 $ 200 1.04858e6 The shape of this is not very table-like though $ {&a. 256 #.inv 2x ^ 100 + ?. 5 2 $ 200 5 2 38 So, since the versions and the keys have to be accessed together (the keys are essentially conditional data with conditional size and meaning), it makes sense to at least explore packing them all together into a binary object into its own inverted table box. There is still ways to pick out parts of the datastructure without unpacking all of it as well. Another way to pack any data structure into a binary object would be compress_zlib lr data (or compress_zlib 3!:1 data). It should compress well if the data is all digits, but you lose the ability to pick out parts of the data without unpacking it all. - Original Message - From: Joe Bogner To: programm...@jsoftware.com Cc: Sent: Wednesday, December 31, 2014 9:28 AM Subject: Re: [Jprogramming] variable integer coding (challenge) Thanks. I missed the point of the variable breakup point but exploring different options below illustrated it for me. Changing the breakup point can encode the numbers into different bit lengths (other than 8) which can then be written to the file/memory. For example, 1021 encoded in 511 breakups would take 18 bits $ #: 511 toVint 1021 2 9 Whereas encoding it as 255 would require 40 bits, which is more than a 32-bit int. This is where I was failing to see the point of encoding larger numbers NB. 5 bytes, 40 bits $ #: 255 toVint 1021 5 8 Without trying the binary representation, I was expecting the breakup point to take the same space. For example, below I would have thought that I'd need to write a NB. 6 bytes 255 toVint 511 toVint 1021 255 255 1 255 255 0 If I understand this correctly, I can see how variable ints could shave off a few bits if the range of numbers is known in advance, which is often the case. Regarding packed strings I've been thinking about it recently as well. I would like to see how it could be used to pack a table of strings (rows and columns). The following string could be a packed representation of a 2x2 table FrankUSATomGermany The binary format could be: [# of rows] [# of columns] [row1-col1 length] [row1-col2 length] The header for the string could be 2 2 5 3 3 7 Or maybe if you wanted to support a variable number of columns (unsure of the usecase of this) [# of rows] [row-1 # of columns] [row1-col1 length] [row1-col2 length] 2 2 5 3 2 3 7 I don't know well it'd perform relative to boxed tables or inverted tables. I would imagine the memory would be reduced for storage but I'd have to test to see how much memory would be used on different operations. I'd be interested in the performance of operations like searching (e.g. find all the rows with a country of Germany) It might also be a safer way of storing user-input text without worrying about escaping delimiters. On Tue, Dec 30, 2014 at 1:18 PM, 'Pascal Jasmin' via Programming wrote: > I also provided some adverbs > > toVint =: 1 : '[: (({."1 ,. 1:) #&, m ,. {:"1) (0, m) #: ]' > fromVint=: 1 : 'm&~: +/;.2 ]' > > these let you set the breakup point to what you wish > > 15 toVint 33 12 17 > 15 15 3 12 15 2 > 511 toVint 1233 > 511 511 211 > > 511 fromVint 511 toVint 1233 444 > 1233 444 > It can provide simple compression. If you have a list of many strings where > almost all of them will fit into a 6bit alphabet, you can still encode a full > 7 bit or 8bit alphabet. On average, you'd save space using 6bit alphabet, > depending on your context. >
Re: [Jprogramming] variable integer coding (challenge)
base64 is essentially taking 3 bytes and storing them as 4. The inverse can take 4 6bit values and pack them into 3 bytes. The J code for base64 is pretty generic to see how to do it for any base. 7 bit values could be packed 8 at a time in 7 bytes. There is a different way to pack 8 x bit values into x bytes. Each byte would store the i'th bit of the 8 values. This may be even faster than base64 type coding. #. |: ?. 8 19 $ 2 104 214 59 183 174 23 31 225 134 149 66 31 85 19 133 1 51 148 28 - Original Message - From: Joe Bogner To: programm...@jsoftware.com Cc: Sent: Wednesday, December 31, 2014 10:02 AM Subject: Re: [Jprogramming] variable integer coding (challenge) Can 19 bits be stored in memory or a file on modern computers without taking up 3 bytes (24 bits)? The only idea that came to mind would some bit packing scheme with multiple items. That seems complicated unless there was a need to store billions of these numbers On Dec 31, 2014 9:28 AM, "Joe Bogner" wrote: > Thanks. I missed the point of the variable breakup point but exploring > different options below illustrated it for me. > > Changing the breakup point can encode the numbers into different bit > lengths (other than 8) which can then be written to the file/memory. > > For example, 1021 encoded in 511 breakups would take 18 bits > >$ #: 511 toVint 1021 > 2 9 > > Whereas encoding it as 255 would require 40 bits, which is more than a > 32-bit int. This is where I was failing to see the point of encoding > larger numbers > > NB. 5 bytes, 40 bits > $ #: 255 toVint 1021 > 5 8 > > Without trying the binary representation, I was expecting the breakup > point to take the same space. For example, below I would have thought > that I'd need to write a > > NB. 6 bytes >255 toVint 511 toVint 1021 > 255 255 1 255 255 0 > > > If I understand this correctly, I can see how variable ints could > shave off a few bits if the range of numbers is known in advance, > which is often the case. > > > Regarding packed strings I've been thinking about it recently as well. > I would like to see how it could be used to pack a table of strings > (rows and columns). > > The following string could be a packed representation of a 2x2 table > > FrankUSATomGermany > > The binary format could be: > > [# of rows] [# of columns] [row1-col1 length] [row1-col2 length] > > The header for the string could be > 2 2 5 3 3 7 > > Or maybe if you wanted to support a variable number of columns (unsure > of the usecase of this) > > [# of rows] [row-1 # of columns] [row1-col1 length] [row1-col2 length] > 2 2 5 3 2 3 7 > > I don't know well it'd perform relative to boxed tables or inverted > tables. I would imagine the memory would be reduced for storage but > I'd have to test to see how much memory would be used on different > operations. I'd be interested in the performance of operations like > searching (e.g. find all the rows with a country of Germany) > > It might also be a safer way of storing user-input text without > worrying about escaping delimiters. > > On Tue, Dec 30, 2014 at 1:18 PM, 'Pascal Jasmin' via Programming > wrote: > > I also provided some adverbs > > > > toVint =: 1 : '[: (({."1 ,. 1:) #&, m ,. {:"1) (0, m) #: ]' > > fromVint=: 1 : 'm&~: +/;.2 ]' > > > > these let you set the breakup point to what you wish > > > > 15 toVint 33 12 17 > > 15 15 3 12 15 2 > > 511 toVint 1233 > > 511 511 211 > > > > 511 fromVint 511 toVint 1233 444 > > 1233 444 > > It can provide simple compression. If you have a list of many strings > where almost all of them will fit into a 6bit alphabet, you can still > encode a full 7 bit or 8bit alphabet. On average, you'd save space using > 6bit alphabet, depending on your context. > > > > The variable string functions I showed, still let you do a substring > search on the packed data. Part of it is disk and memory compression > (don't expand until you need to, and a string takes much less memory than a > list of numbers < 256), but part of it is not being forced in design to > determine what the impossible cutoff number is. > > > > A big advantage related to J is having binary data records. If you > encode the length of the binary data, you no longer have to box them if a > trailing 0 or space would be difficult to know whether it is a fill or > intentional. > > > > Beyond binary data, there is dumb stuff such as storing addresses. Most > people have just 1, Most fit within 255 bytes. Usually no one cares about > address info ex
Re: [Jprogramming] variable integer coding (challenge)
Also, if you have only 4 19 bit values, you can pack them up tighter _2 (16&#.)\ #. |: ?. 4 19 $ 2 109 59 161 30 136 80 64 129 56 1 Non multiples of 8 would just generally leave some trailing 0s on decode, which could simply be understood as invalid. - Original Message - From: 'Pascal Jasmin' via Programming To: "programm...@jsoftware.com" Cc: Sent: Wednesday, December 31, 2014 11:40 AM Subject: Re: [Jprogramming] variable integer coding (challenge) base64 is essentially taking 3 bytes and storing them as 4. The inverse can take 4 6bit values and pack them into 3 bytes. The J code for base64 is pretty generic to see how to do it for any base. 7 bit values could be packed 8 at a time in 7 bytes. There is a different way to pack 8 x bit values into x bytes. Each byte would store the i'th bit of the 8 values. This may be even faster than base64 type coding. #. |: ?. 8 19 $ 2 104 214 59 183 174 23 31 225 134 149 66 31 85 19 133 1 51 148 28 - Original Message - From: Joe Bogner To: programm...@jsoftware.com Cc: Sent: Wednesday, December 31, 2014 10:02 AM Subject: Re: [Jprogramming] variable integer coding (challenge) Can 19 bits be stored in memory or a file on modern computers without taking up 3 bytes (24 bits)? The only idea that came to mind would some bit packing scheme with multiple items. That seems complicated unless there was a need to store billions of these numbers On Dec 31, 2014 9:28 AM, "Joe Bogner" wrote: > Thanks. I missed the point of the variable breakup point but exploring > different options below illustrated it for me. > > Changing the breakup point can encode the numbers into different bit > lengths (other than 8) which can then be written to the file/memory. > > For example, 1021 encoded in 511 breakups would take 18 bits > >$ #: 511 toVint 1021 > 2 9 > > Whereas encoding it as 255 would require 40 bits, which is more than a > 32-bit int. This is where I was failing to see the point of encoding > larger numbers > > NB. 5 bytes, 40 bits > $ #: 255 toVint 1021 > 5 8 > > Without trying the binary representation, I was expecting the breakup > point to take the same space. For example, below I would have thought > that I'd need to write a > > NB. 6 bytes >255 toVint 511 toVint 1021 > 255 255 1 255 255 0 > > > If I understand this correctly, I can see how variable ints could > shave off a few bits if the range of numbers is known in advance, > which is often the case. > > > Regarding packed strings I've been thinking about it recently as well. > I would like to see how it could be used to pack a table of strings > (rows and columns). > > The following string could be a packed representation of a 2x2 table > > FrankUSATomGermany > > The binary format could be: > > [# of rows] [# of columns] [row1-col1 length] [row1-col2 length] > > The header for the string could be > 2 2 5 3 3 7 > > Or maybe if you wanted to support a variable number of columns (unsure > of the usecase of this) > > [# of rows] [row-1 # of columns] [row1-col1 length] [row1-col2 length] > 2 2 5 3 2 3 7 > > I don't know well it'd perform relative to boxed tables or inverted > tables. I would imagine the memory would be reduced for storage but > I'd have to test to see how much memory would be used on different > operations. I'd be interested in the performance of operations like > searching (e.g. find all the rows with a country of Germany) > > It might also be a safer way of storing user-input text without > worrying about escaping delimiters. > > On Tue, Dec 30, 2014 at 1:18 PM, 'Pascal Jasmin' via Programming > wrote: > > I also provided some adverbs > > > > toVint =: 1 : '[: (({."1 ,. 1:) #&, m ,. {:"1) (0, m) #: ]' > > fromVint=: 1 : 'm&~: +/;.2 ]' > > > > these let you set the breakup point to what you wish > > > > 15 toVint 33 12 17 > > 15 15 3 12 15 2 > > 511 toVint 1233 > > 511 511 211 > > > > 511 fromVint 511 toVint 1233 444 > > 1233 444 > > It can provide simple compression. If you have a list of many strings > where almost all of them will fit into a 6bit alphabet, you can still > encode a full 7 bit or 8bit alphabet. On average, you'd save space using > 6bit alphabet, depending on your context. > > > > The variable string functions I showed, still let you do a substring > search on the packed data. Part of it is disk and memory compression > (don't expand until you need to, and a string takes much less memory than a > list of numbers < 256), but part of it is not being forced in design to > determin
[Jprogramming] an alternative to &. - and fun with conjunctions
A conjunction that returns an adverb and applies its 2 arguments before and after the adverb's parameter. B =: 2 : '(@: u)(v @:)' >: +:B -: 2 2.5 >: &.+: 2 2.5 >: dfh B hfd '1a' 1b The verbs are placed counterintuitively under the presumption that the u verb will be longer, and so this avoids parentheses. Also the u side is what modifies the adverb parameter. dfh and hfd are not defined as inverses, and this also lets you setup up bracketed operations independently of they being inverses. A bit more complex of a between conjunction, where the closer also uses the same y parameter (as its x): Bwy =: 2 : ' 1 : (''] ('' , v lrA , '') [: '', '' u ('' , (u lrA) ,'')"_'')' sfX =: 1 : '][u' NB. apply u, but keep y as the result. +: +:Bwy(-~) ] -~ [: +: +:"_ +: +:Bwy(-~) 2 6 for a useful example, '1' fwrite jpath '~temp/1.cnt' 1 withFile =: &.". fread Bwy (fwrite~ sfX) NB. adverb that will apply operation to file then save it. >: withFile ] (] [ fwrite~) [: >:&.". fread"_ >: withFile jpath '~temp/1.cnt' 2 Another bracketing type application is for "ensure even if error" code. Can't seem to decide what should be u and v, as this is inverted compared to above: BetweenE =: 2 : ' 1 : (''([: ('' , u lrA , '') [: '', '' u ('' , (v lrA) ,'')"_) :: ('' , u lrA , '')'' )' -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] During lulls in the games can you simplify this code?
elegance to me is having a one line version so as to avoid running multiple lines in order. the first chart is easy + table i.11 the basis for the second one is also pretty easy - table i.10 though you want to clean it of negative values ([: _:^:(0 > ])"0 -/~) i.10 0 _ _ _ _ _ _ _ _ _ 1 0 _ _ _ _ _ _ _ _ 2 1 0 _ _ _ _ _ _ _ 3 2 1 0 _ _ _ _ _ _ 4 3 2 1 0 _ _ _ _ _ 5 4 3 2 1 0 _ _ _ _ 6 5 4 3 2 1 0 _ _ _ 7 6 5 4 3 2 1 0 _ _ 8 7 6 5 4 3 2 1 0 _ 9 8 7 6 5 4 3 2 1 0 to get the formatting, this is actually a small change to the table adverb, though looks scary table2 =: 1 : ('(((#~LF-.@e.])5!:5<''u'');,.y),.({.;}.)":y, u y';':'; '(((#~LF-.@e.])5!:5<''u'');,.y),.({.;}.)":x,y u x') ([: _:^:(0 > ])"0 -/~) table2 i.10 ┌┬───┐ │[: _:^:(0 > ])"0 -/~│0 1 2 3 4 5 6 7 8 9│ ├┼───┤ │0 │0 _ _ _ _ _ _ _ _ _│ │1 │1 0 _ _ _ _ _ _ _ _│ │2 │2 1 0 _ _ _ _ _ _ _│ │3 │3 2 1 0 _ _ _ _ _ _│ │4 │4 3 2 1 0 _ _ _ _ _│ │5 │5 4 3 2 1 0 _ _ _ _│ │6 │6 5 4 3 2 1 0 _ _ _│ │7 │7 6 5 4 3 2 1 0 _ _│ │8 │8 7 6 5 4 3 2 1 0 _│ │9 │9 8 7 6 5 4 3 2 1 0│ └┴───┘ can be called dyadically too: (i.10) ([: _:^:(0 > ])"0 -/~) table2 4 + i.10 From: Linda Alvord To: programm...@jsoftware.com Sent: Sunday, January 4, 2015 11:34 AM Subject: [Jprogramming] During lulls in the games can you simplify this code? In the beginning of J TECH Grade 3, I am summarizing the facts that students should have learned in Grade 2 at the outset. Addition and Subtraction are a pair of inverse functions. Students learned addition facts for numbers 0 to 10. The sums range from 0 to 20. Thus the inverse must include the numbers from 0 - 20 divided by 1 to 10. You can't divide by 0. Students haven't met negative numbers. So here's the charts I want. Do you know any ways I could do this more simply or elegantly? A=:":((i.20)>:/i.10)*(i.20)-/i.10 B=:(|._3*i.10),10$0 C=:B|.!.' '"0 1 A D=:(-B)|.!.' '"0 1 C TOP=: (<' - '),<}.,' ',"1":,.>:i.10 BOT=:(<,.>:i.20),http://www.jsoftware.com/forums.htm -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] During lulls in the games can you simplify this code?
actually there is a way to get something like the 2nd table with the default table adverb (i.10) _:^:(0 > ])@- table 4 + i.10 or _:^:(0&>)@- table 4 + i.10 - Original Message ----- From: 'Pascal Jasmin' via Programming To: "programm...@jsoftware.com" Cc: Sent: Sunday, January 4, 2015 1:10 PM Subject: Re: [Jprogramming] During lulls in the games can you simplify this code? elegance to me is having a one line version so as to avoid running multiple lines in order. the first chart is easy + table i.11 the basis for the second one is also pretty easy - table i.10 though you want to clean it of negative values ([: _:^:(0 > ])"0 -/~) i.10 0 _ _ _ _ _ _ _ _ _ 1 0 _ _ _ _ _ _ _ _ 2 1 0 _ _ _ _ _ _ _ 3 2 1 0 _ _ _ _ _ _ 4 3 2 1 0 _ _ _ _ _ 5 4 3 2 1 0 _ _ _ _ 6 5 4 3 2 1 0 _ _ _ 7 6 5 4 3 2 1 0 _ _ 8 7 6 5 4 3 2 1 0 _ 9 8 7 6 5 4 3 2 1 0 to get the formatting, this is actually a small change to the table adverb, though looks scary table2 =: 1 : ('(((#~LF-.@e.])5!:5<''u'');,.y),.({.;}.)":y, u y';':'; '(((#~LF-.@e.])5!:5<''u'');,.y),.({.;}.)":x,y u x') ([: _:^:(0 > ])"0 -/~) table2 i.10 ┌┬───┐ │[: _:^:(0 > ])"0 -/~│0 1 2 3 4 5 6 7 8 9│ ├┼───┤ │0 │0 _ _ _ _ _ _ _ _ _│ │1 │1 0 _ _ _ _ _ _ _ _│ │2 │2 1 0 _ _ _ _ _ _ _│ │3 │3 2 1 0 _ _ _ _ _ _│ │4 │4 3 2 1 0 _ _ _ _ _│ │5 │5 4 3 2 1 0 _ _ _ _│ │6 │6 5 4 3 2 1 0 _ _ _│ │7 │7 6 5 4 3 2 1 0 _ _│ │8 │8 7 6 5 4 3 2 1 0 _│ │9 │9 8 7 6 5 4 3 2 1 0│ └┴───┘ can be called dyadically too: (i.10) ([: _:^:(0 > ])"0 -/~) table2 4 + i.10 From: Linda Alvord To: programm...@jsoftware.com Sent: Sunday, January 4, 2015 11:34 AM Subject: [Jprogramming] During lulls in the games can you simplify this code? In the beginning of J TECH Grade 3, I am summarizing the facts that students should have learned in Grade 2 at the outset. Addition and Subtraction are a pair of inverse functions. Students learned addition facts for numbers 0 to 10. The sums range from 0 to 20. Thus the inverse must include the numbers from 0 - 20 divided by 1 to 10. You can't divide by 0. Students haven't met negative numbers. So here's the charts I want. Do you know any ways I could do this more simply or elegantly? A=:":((i.20)>:/i.10)*(i.20)-/i.10 B=:(|._3*i.10),10$0 C=:B|.!.' '"0 1 A D=:(-B)|.!.' '"0 1 C TOP=: (<' - '),<}.,' ',"1":,.>:i.10 BOT=:(<,.>:i.20),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] During lulls in the games can you simplify this code?
this keeps stuff aligned ('_';' ') rplc~"1 ": _:^:(0 > ])"0 ] 10 10 $ i: 12 ('_';' ') rplc~"1 ": _:^:(0 > ])@-/~ i. 12 this might be slightly cheating: ('_';' ') rplc~"1 ": _:^:(0 > ])@- table i. 12 From: robert therriault To: programm...@jsoftware.com Sent: Sunday, January 4, 2015 9:33 PM Subject: Re: [Jprogramming] During lulls in the games can you simplify this code? No, I was thinking something more positive than that :) Something that would take an array with negatives 3 6 4 12 _2 10 _3 0 _4 and remove them completely to display this 3 6 4 1210 0 Still haven't done it though. Cheers, bob On Jan 4, 2015, at 1:24 PM, Raul Miller wrote: > Like this? > > negatives=:adverb define > : > ~.(#~ 0&>),x u/ y > ) > > (1+i.20) -negatives 1+i.10 > _1 _2 _3 _4 _5 _6 _7 _8 _9 > > Seems like overkill, for this task, since the the point of this exercise > is, I expect, building the groundwork for introducing negative numbers. > > -- > Raul > > On Sun, Jan 4, 2015 at 2:54 PM, robert therriault > wrote: > >> Linda, >> >> What are these games you speak of? (just kidding, Go 'Hawks - oh yeah >> that's next week) >> >> After a long and circuitous route that I won't go into, and with the >> benefit of Raul and Pascal's responses, I came up with this: >> >> postable=:1 : (':'; '(((#~LF-.@e.])5!:5<''u'');,.y),.({.;}.)(#~ >> -.@(+./\@(''_''=])))"1@":x,y u/x')~ >> (i.21)- postable i.11 >> ┌──┬─┐ >> │- │ 0 1 2 3 4 5 6 7 8 9 10│ >> ├──┼─┤ >> │ 0│ 0 │ >> │ 1│ 1 0│ >> │ 2│ 2 1 0 │ >> │ 3│ 3 2 1 0 │ >> │ 4│ 4 3 2 1 0 │ >> │ 5│ 5 4 3 2 1 0│ >> │ 6│ 6 5 4 3 2 1 0 │ >> │ 7│ 7 6 5 4 3 2 1 0 │ >> │ 8│ 8 7 6 5 4 3 2 1 0 │ >> │ 9│ 9 8 7 6 5 4 3 2 1 0│ >> │10│10 9 8 7 6 5 4 3 2 1 0│ >> │11│11 10 9 8 7 6 5 4 3 2 1│ >> │12│12 11 10 9 8 7 6 5 4 3 2│ >> │13│13 12 11 10 9 8 7 6 5 4 3│ >> │14│14 13 12 11 10 9 8 7 6 5 4│ >> │15│15 14 13 12 11 10 9 8 7 6 5│ >> │16│16 15 14 13 12 11 10 9 8 7 6│ >> │17│17 16 15 14 13 12 11 10 9 8 7│ >> │18│18 17 16 15 14 13 12 11 10 9 8│ >> │19│19 18 17 16 15 14 13 12 11 10 9│ >> │20│20 19 18 17 16 15 14 13 12 11 10│ >> └──┴─┘ >> table >> 1 : (':'; '(((#~LF-.@e.])5!:5<''u'');,.y),.({.;}.)":x,y u/x')~ >> (i.21)- table i.11 >> ┌──┬─┐ >> │- │ 0 1 2 3 4 5 6 7 8 9 10│ >> ├──┼─┤ >> │ 0│ 0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _10│ >> │ 1│ 1 0 _1 _2 _3 _4 _5 _6 _7 _8 _9│ >> │ 2│ 2 1 0 _1 _2 _3 _4 _5 _6 _7 _8│ >> │ 3│ 3 2 1 0 _1 _2 _3 _4 _5 _6 _7│ >> │ 4│ 4 3 2 1 0 _1 _2 _3 _4 _5 _6│ >> │ 5│ 5 4 3 2 1 0 _1 _2 _3 _4 _5│ >> │ 6│ 6 5 4 3 2 1 0 _1 _2 _3 _4│ >> │ 7│ 7 6 5 4 3 2 1 0 _1 _2 _3│ >> │ 8│ 8 7 6 5 4 3 2 1 0 _1 _2│ >> │ 9│ 9 8 7 6 5 4 3 2 1 0 _1│ >> │10│10 9 8 7 6 5 4 3 2 1 0│ >> │11│11 10 9 8 7 6 5 4 3 2 1│ >> │12│12 11 10 9 8 7 6 5 4 3 2│ >> │13│13 12 11 10 9 8 7 6 5 4 3│ >> │14│14 13 12 11 10 9 8 7 6 5 4│ >> │15│15 14 13 12 11 10 9 8 7 6 5│ >> │16│16 15 14 13 12 11 10 9 8 7 6│ >> │17│17 16 15 14 13 12 11 10 9 8 7│ >> │18│18 17 16 15 14 13 12 11 10 9 8│ >> │19│19 18 17 16 15 14 13 12 11 10 9│ >> │20│20 19 18 17 16 15 14 13 12 11 10│ >> └──┴─┘ >> >> postable differs from table in one significant way. After the results of >> the table have been formatted, it uses (#~ -.@(+./\@(''_''=])))"1 to clean >> them (double quotes needed around '_' because it is sitting inside of an >> adverb declaration string). What this fragment does is to look for >> instances of '_' in each line and then replaces the rest of the line with >> blanks. This works as long as the negative values are contiguous - I am >> still looking at the general case of cherry picking negative val
Re: [Jprogramming] Forward fill w/o looping
dyadic ;. is your usual friend in these cases. Though Raul has often found even more elegant approaches. a: (-.@= <;.1 ] )'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' ┌──┬─┬───┬───┬─┐ │┌──┬┬┐│┌──┬┐│┌───┬┬┐│┌───┬┬┐│┌──┬┐│ ││Hi│Hohee│haw│Yo│││ │└──┴┴┘│└──┴┘│└───┴┴┘│└───┴┴┘│└──┴┘│ └──┴─┴───┴───┴─┘ ; (# # {. )each a: (-.@= <;.1 ] )'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' ┌──┬──┬──┬──┬──┬───┬───┬───┬───┬───┬───┬──┬──┐ │Hi│Hi│Hi│Ho│Ho│hee│hee│hee│haw│haw│haw│Yo│Yo│ └──┴──┴──┴──┴──┴───┴───┴───┴───┴───┴───┴──┴──┘ its a bit more complicated with possible leading blank: (this still works without leading blank) ; (# # {. ) each a: (] <;.1~ 1 (0}) -.@= )'';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' ┌┬──┬──┬──┬──┬──┬───┬───┬───┬───┬───┬───┬──┬──┐ ││Hi│Hi│Hi│Ho│Ho│hee│hee│hee│haw│haw│haw│Yo│Yo│ └┴──┴──┴──┴──┴──┴───┴───┴───┴───┴───┴───┴──┴──┘ - Original Message - From: Devon McCormick To: J-programming forum Cc: Sent: Monday, January 5, 2015 11:06 AM Subject: [Jprogramming] Forward fill w/o looping I just threw together a short J solution that does what I want but it uses a loop and a conditional. I'm thinking there's got to be some kind of loopless prefix sort of solution but am at a loss to come up with it. My code looks like this: fillEmptyFwd=: 3 : 0 for_ix. i.<:#y do. if. 0=#>y{~>:ix do. y=. (ix{y) (>:ix)}y end. end. y ) An example usage would be this: fillEmptyFwd '';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' ++--+--+--+--+--+---+---+---+---+---+---+--+--+ ||Hi|Hi|Hi|Ho|Ho|hee|hee|hee|haw|haw|haw|Yo|Yo| ++--+--+--+--+--+---+---+---+---+---+---+--+--+ Any ideas on something less loopy/conditional? -- 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] Forward fill w/o looping
as a single more general function a: ;@:(] <@(# # {. );.1~ 1 (0}) -.@= )'';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' 0 ;@:(] <@(# # {. );.1~ 1 (0}) -.@= ) 0 33 0 0 22 0 0 11 0 0 0 0 33 33 33 22 22 22 11 11 11 11 - Original Message - From: 'Pascal Jasmin' via Programming To: "programm...@jsoftware.com" Cc: Sent: Monday, January 5, 2015 11:26 AM Subject: Re: [Jprogramming] Forward fill w/o looping dyadic ;. is your usual friend in these cases. Though Raul has often found even more elegant approaches. a: (-.@= <;.1 ] )'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' ┌──┬─┬───┬───┬─┐ │┌──┬┬┐│┌──┬┐│┌───┬┬┐│┌───┬┬┐│┌──┬┐│ ││Hi│Hohee│haw│Yo│││ │└──┴┴┘│└──┴┘│└───┴┴┘│└───┴┴┘│└──┴┘│ └──┴─┴───┴───┴─┘ ; (# # {. )each a: (-.@= <;.1 ] )'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' ┌──┬──┬──┬──┬──┬───┬───┬───┬───┬───┬───┬──┬──┐ │Hi│Hi│Hi│Ho│Ho│hee│hee│hee│haw│haw│haw│Yo│Yo│ └──┴──┴──┴──┴──┴───┴───┴───┴───┴───┴───┴──┴──┘ its a bit more complicated with possible leading blank: (this still works without leading blank) ; (# # {. ) each a: (] <;.1~ 1 (0}) -.@= )'';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' ┌┬──┬──┬──┬──┬──┬───┬───┬───┬───┬───┬───┬──┬──┐ ││Hi│Hi│Hi│Ho│Ho│hee│hee│hee│haw│haw│haw│Yo│Yo│ └┴──┴──┴──┴──┴──┴───┴───┴───┴───┴───┴───┴──┴──┘ - Original Message - From: Devon McCormick To: J-programming forum Cc: Sent: Monday, January 5, 2015 11:06 AM Subject: [Jprogramming] Forward fill w/o looping I just threw together a short J solution that does what I want but it uses a loop and a conditional. I'm thinking there's got to be some kind of loopless prefix sort of solution but am at a loss to come up with it. My code looks like this: fillEmptyFwd=: 3 : 0 for_ix. i.<:#y do. if. 0=#>y{~>:ix do. y=. (ix{y) (>:ix)}y end. end. y ) An example usage would be this: fillEmptyFwd '';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' ++--+--+--+--+--+---+---+---+---+---+---+--+--+ ||Hi|Hi|Hi|Ho|Ho|hee|hee|hee|haw|haw|haw|Yo|Yo| ++--+--+--+--+--+---+---+---+---+---+---+--+--+ Any ideas on something less loopy/conditional? -- 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] Forward fill w/o looping
a verbed variation of Roger's (] (({.@:[ , #~) {~ +/\@:] ) [: * #&>) '';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' - Original Message - From: Roger Hui To: Programming forum Cc: Sent: Monday, January 5, 2015 11:59 AM Subject: Re: [Jprogramming] Forward fill w/o looping t=: '';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' fillEmptyFwd t ┌┬──┬──┬──┬──┬──┬───┬───┬───┬───┬───┬───┬──┬──┐ ││Hi│Hi│Hi│Ho│Ho│hee│hee│hee│haw│haw│haw│Yo│Yo│ └┴──┴──┴──┴──┴──┴───┴───┴───┴───┴───┴───┴──┴──┘ (({.t),b#t) {~ +/\b=: *#&>t ┌┬──┬──┬──┬──┬──┬───┬───┬───┬───┬───┬───┬──┬──┐ ││Hi│Hi│Hi│Ho│Ho│hee│hee│hee│haw│haw│haw│Yo│Yo│ └┴──┴──┴──┴──┴──┴───┴───┴───┴───┴───┴───┴──┴──┘ On Mon, Jan 5, 2015 at 8:06 AM, Devon McCormick wrote: > I just threw together a short J solution that does what I want but it uses > a loop and a conditional. I'm thinking there's got to be some kind of > loopless prefix sort of solution but am at a loss to come up with it. > > My code looks like this: > > fillEmptyFwd=: 3 : 0 > for_ix. i.<:#y do. > if. 0=#>y{~>:ix do. y=. (ix{y) (>:ix)}y end. > end. > y > ) > > An example usage would be this: > >fillEmptyFwd '';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' > ++--+--+--+--+--+---+---+---+---+---+---+--+--+ > ||Hi|Hi|Hi|Ho|Ho|hee|hee|hee|haw|haw|haw|Yo|Yo| > ++--+--+--+--+--+---+---+---+---+---+---+--+--+ > > Any ideas on something less loopy/conditional? > > -- > 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] variable integer coding (challenge)
I'm not sure this is the same problem, unless you are trying to encode within a range of lattitudes that include dense civilization, and longitudes that exclude oceans. but the 32bit binary rep of -17998321 32 ($!.1)&.|. #: -17998321 1 1 1 1 1 1 1 0 1 1 1 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 1 1 1 1 though the "memcopy" version is simpler. #: 256 #. |. a.i. 2 ic _17998321 1 1 1 1 1 1 1 0 1 1 1 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 1 1 1 1 -&4294967296^:(>&2147483648) 256 #. |. a.i. 2 ic _17998321 _17998321 -&4294967296^:(>&2147483648) 256 #. |. a.i. 2 ic 17998321 17998321 I'm not sure if the |. step is only for non macs. - Original Message - From: Vijay Lulla To: programm...@jsoftware.com Cc: Sent: Tuesday, January 6, 2015 11:38 AM Subject: Re: [Jprogramming] variable integer coding (challenge) I have followed this thread with interest. Much of this discussion is relevant to https://developers.google.com/maps/documentation/utilities/polylinealgorithm . Like Joe, I also enjoyed playing at bits level and was impressed by how easy J makes such explorations. Unfortunately, I couldn't generate all the encoded values in the example table listed on the page. Maybe others in this group might enjoy exploring this algorithm. Thanks for the great discussion. On Wed, Dec 31, 2014 at 3:15 PM, Joe Bogner wrote: > Thanks. I couldn't follow the examples so I worked through it on my > own. Sharing it here for anyone else who's following. I switched to 9 > bits instead of 19 to simplify the example > >NB. 300 needs 9 bits to be expressed >$ #: 300 > 9 > >NB. Show 4 9 bit numbers >$ #: 300 301 302 303 > 4 9 > > Writing those 4 numbers would take 16 bytes[1] since J ints are 4 > bytes as well as C > > We can compress it down to 5 bytes if we pack all the bits together: > >] packed=. #. _8[\ , #: 300 301 302 303 > 150 75 101 210 240 > >$ packed > 5 > > Those 5 bytes could be written to a file and re-read > > If I knew in advance that those numbers were 9 bits, it can be reversed > >#. _9[\, #: packed > 300 301 302 303 0 > > We could also pack it into 8 bytes (two 32 bit integers), but I don't > see an advantage of that over packing into a single byte (8 bit) > >] packed=. #. _32[\ , #: 300 301 302 303 > 2.52152e9 4.02653e9 > >#. _9[\, #: packed > 300 301 302 303 0 0 0 0 > > > This may be elementary for some but I haven't worked at this level in > years so I enjoyed playing with it > > > > > [1] - http://www.jsoftware.com/help/learning/27.htm > > On Wed, Dec 31, 2014 at 11:51 AM, 'Pascal Jasmin' via Programming > wrote: > > Also, if you have only 4 19 bit values, you can pack them up tighter > > > > _2 (16&#.)\ #. |: ?. 4 19 $ 2 > > 109 59 161 30 136 80 64 129 56 1 > > > > Non multiples of 8 would just generally leave some trailing 0s on > decode, which could simply be understood as invalid. > > > > > > - Original Message - > > From: 'Pascal Jasmin' via Programming > > To: "programm...@jsoftware.com" > > Cc: > > Sent: Wednesday, December 31, 2014 11:40 AM > > Subject: Re: [Jprogramming] variable integer coding (challenge) > > > > base64 is essentially taking 3 bytes and storing them as 4. The inverse > can take 4 6bit values and pack them into 3 bytes. The J code for base64 > is pretty generic to see how to do it for any base. 7 bit values could be > packed 8 at a time in 7 bytes. > > > > There is a different way to pack 8 x bit values into x bytes. Each byte > would store the i'th bit of the 8 values. This may be even faster than > base64 type coding. > > > > #. |: ?. 8 19 $ 2 > > 104 214 59 183 174 23 31 225 134 149 66 31 85 19 133 1 51 148 28 > > > > > > - Original Message - > > From: Joe Bogner > > To: programm...@jsoftware.com > > Cc: > > Sent: Wednesday, December 31, 2014 10:02 AM > > Subject: Re: [Jprogramming] variable integer coding (challenge) > > > > Can 19 bits be stored in memory or a file on modern computers without > > taking up 3 bytes (24 bits)? The only idea that came to mind would some > bit > > packing scheme with multiple items. That seems complicated unless there > was > > a need to store billions of these numbers > > > > On Dec 31, 2014 9:28 AM, "Joe Bogner" wrote: > > > >> Thanks. I missed the point of the variable breakup point but exploring > >> different options below illustrated it for me. > >> > >> Changing the breakup point can encode the numbers into di
Re: [Jprogramming] Jd information
Perhaps there could be a warning that a key is needed on load 'jd' But a user could still go through the tutorial by not enforcing the key for purposes of hard coded tutorial file names. This would allow someone to look at JD while waiting for a key. No one would ever try to store real data in shadowed tutorial filenames if any update of the jd addon can overwrite these files. The use scenarios are "I wonder if Jd could help with this?" or "While I'm in your office, jd could do this" which can get interupted by a key process. - Original Message - From: Eric Iverson To: Programming forum Cc: Sent: Tuesday, January 6, 2015 12:18 PM Subject: [Jprogramming] Jd information If one wanted to know more about Jd without bothering with a key or the tutorials: 1. install Jd with JAL 2. browse to file ~addons/data/jd/doc/toc.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
Re: [Jprogramming] variable integer coding (challenge)
thank you Raul, I think this "decryption" function is still needed though? -&4294967296^:(>&2147483648) #. (32#2)#: _17998321 _17998321 -&4294967296^:(>&2147483648) #. (32#2)#: 17998321 17998321 - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Tuesday, January 6, 2015 1:43 PM Subject: Re: [Jprogramming] variable integer coding (challenge) The &.|. in ($!.1)&.|. is so the 1s you are padding with appear on the left, rather than on the right. Another way of accomplishing that would be like this: _32 {.!.1 #:-17998321 1 1 1 1 1 1 1 0 1 1 1 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 1 1 1 1 But note that there's a problem here (with both of these approaches): 32 ($!.1)&.|. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...padding on the left with 1s is only valid for negative numbers. Meanwhile, #: 256 #. |. a.i. 2 ic _17998321 1 1 1 1 1 1 1 0 1 1 1 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 1 1 1 1 ... so the |. which appears in that expression works the same way on probably any intel machine and would probably be relevant in most contexts (though I've not tested on ARM processor, and I'm not even sure if current versions of J run on ARM... and since ARM is "bi-endian" I'm not sure what "native" would mean in that context - but I guess it would make sense for ARM handling to mimic intel handling). But there's an even simpler approach: (32#2)#:_17998321 1 1 1 1 1 1 1 0 1 1 1 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 1 1 1 1 Simplicity is a virtue? Thanks, -- Raul On Tue, Jan 6, 2015 at 12:44 PM, 'Pascal Jasmin' via Programming wrote: > I'm not sure this is the same problem, unless you are trying to encode within > a range of lattitudes that include dense civilization, and longitudes that > exclude oceans. > > but the 32bit binary rep of -17998321 > > 32 ($!.1)&.|. #: -17998321 > 1 1 1 1 1 1 1 0 1 1 1 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 1 1 1 1 > > though the "memcopy" version is simpler. > > #: 256 #. |. a.i. 2 ic _17998321 > 1 1 1 1 1 1 1 0 1 1 1 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 1 1 1 1 > > -&4294967296^:(>&2147483648) 256 #. |. a.i. 2 ic _17998321 > _17998321 > -&4294967296^:(>&2147483648) 256 #. |. a.i. 2 ic 17998321 > 17998321 > > > I'm not sure if the |. step is only for non macs. > > > > - Original Message - > From: Vijay Lulla > To: programm...@jsoftware.com > Cc: > Sent: Tuesday, January 6, 2015 11:38 AM > Subject: Re: [Jprogramming] variable integer coding (challenge) > > I have followed this thread with interest. Much of this discussion is > relevant to > https://developers.google.com/maps/documentation/utilities/polylinealgorithm > . Like Joe, I also enjoyed playing at bits level and was impressed by how > easy J makes such explorations. Unfortunately, I couldn't generate all the > encoded values in the example table listed on the page. Maybe others in > this group might enjoy exploring this algorithm. > > Thanks for the great discussion. > > On Wed, Dec 31, 2014 at 3:15 PM, Joe Bogner wrote: > >> Thanks. I couldn't follow the examples so I worked through it on my >> own. Sharing it here for anyone else who's following. I switched to 9 >> bits instead of 19 to simplify the example >> >>NB. 300 needs 9 bits to be expressed >>$ #: 300 >> 9 >> >>NB. Show 4 9 bit numbers >>$ #: 300 301 302 303 >> 4 9 >> >> Writing those 4 numbers would take 16 bytes[1] since J ints are 4 >> bytes as well as C >> >> We can compress it down to 5 bytes if we pack all the bits together: >> >>] packed=. #. _8[\ , #: 300 301 302 303 >> 150 75 101 210 240 >> >>$ packed >> 5 >> >> Those 5 bytes could be written to a file and re-read >> >> If I knew in advance that those numbers were 9 bits, it can be reversed >> >>#. _9[\, #: packed >> 300 301 302 303 0 >> >> We could also pack it into 8 bytes (two 32 bit integers), but I don't >> see an advantage of that over packing into a single byte (8 bit) >> >>] packed=. #. _32[\ , #: 300 301 302 303 >> 2.52152e9 4.02653e9 >> >>#. _9[\, #: packed >> 300 301 302 303 0 0 0 0 >> >> >> This may be elementary for some but I haven't worked at this level in >> years so I enjoyed playing with it >> >> >> >> >> [1] - http://www.jsoftware.com/help/learning/27.htm >> >> On Wed, Dec 31, 2014 at 11:51 AM, 'Pascal Jasmin' via Programming >> wrote: >> > Also, if you ha