Replace gray by gray=. [: -. [: (= (_1 |.!.0"1 ])) 2&#.^:_1 to allow large(r) Gray codes.
See solution 10 on http://www.jsoftware.com/jwiki/Puzzles/Gray%20Code ('0.4';'c12.0') (8!:2) ts' Gray i.524288' NB. 54288=2^19 0.0247 33,556,352 ('0.4';'c12.0') (8!:2) ts' gray i.524288' NB. 54288=2^19 0.4365 293,615,616 ('0.4';'c12.0') (8!:2) ts' #:([: ({: (({. * #@]) ,@:+ ($ (,: |.))) ((* #) ,@:+ # $ (,: |.))^:({.`(0: , 1:))) ] (] , 2: ^ (- 2&^)) <.@(2&^.)@<:) 19' 0.0182 26,231,168 (gray i.524288)-: #:([: ({: (({. * #@]) ,@:+ ($ (,: |.))) ((* #) ,@:+ # $ (,: |.))^:({.`(0: , 1:))) ] (] , 2: ^ (- 2&^)) <.@(2&^.)@<:) 19 1 (Gray i.524288)-: #:([: ({: (({. * #@]) ,@:+ ($ (,: |.))) ((* #) ,@:+ # $ (,: |.))^:({.`(0: , 1:))) ] (] , 2: ^ (- 2&^)) <.@(2&^.)@<:) 19 1 R.E. Boss (Add your info to http://www.jsoftware.com/jwiki/Community/Demographics ) > -----Original Message----- > From: [email protected] [mailto:programming- > [email protected]] On Behalf Of Jose Mario Quintana > Sent: zondag 17 november 2013 22:28 > To: Programming forum > Subject: Re: [Jprogramming] Sets > > "Grey" and gray are related but they take different arguments and produce > different results. However, we can compare Gray (derived from Grey) and > gray. Gray is shorter than gray, > > ( gray=. [: -. [: (= (_1 |.!.0"1 ])) bin f. ) NB. Fixed > [: -. [: (= (_1 |.!.0"1 ])) 2 2 2 2&#: > > ( Gray=. #: @: (22 b. <.@:-:) ) NB. Fixed > #:@:(22 b. <.@:-:) > > Gray and gray produce the same result for the given argument, > > (Gray -: gray) i.16 > 1 > > Gray is more efficient than gray, > > 100 st'gray i.16' > ┌────┬─────────────┐ > │2112│4.55809702e_6│ > └────┴─────────────┘ > 100 st'Gray i.16' > ┌────┬─────────────┐ > │1408│3.12123995e_6│ > └────┴─────────────┘ > > and it is more general, > > (Gray ; gray) i.32 > ┌─────────┬───────┐ > │0 0 0 0 0│0 0 0 0│ > │0 0 0 0 1│0 0 0 1│ > │0 0 0 1 1│0 0 1 1│ > │0 0 0 1 0│0 0 1 0│ > │0 0 1 1 0│0 1 1 0│ > │0 0 1 1 1│0 1 1 1│ > │0 0 1 0 1│0 1 0 1│ > │0 0 1 0 0│0 1 0 0│ > │0 1 1 0 0│1 1 0 0│ > │0 1 1 0 1│1 1 0 1│ > │0 1 1 1 1│1 1 1 1│ > │0 1 1 1 0│1 1 1 0│ > │0 1 0 1 0│1 0 1 0│ > │0 1 0 1 1│1 0 1 1│ > │0 1 0 0 1│1 0 0 1│ > │0 1 0 0 0│1 0 0 0│ > │1 1 0 0 0│0 0 0 0│ > │1 1 0 0 1│0 0 0 1│ > │1 1 0 1 1│0 0 1 1│ > │1 1 0 1 0│0 0 1 0│ > │1 1 1 1 0│0 1 1 0│ > │1 1 1 1 1│0 1 1 1│ > │1 1 1 0 1│0 1 0 1│ > │1 1 1 0 0│0 1 0 0│ > │1 0 1 0 0│1 1 0 0│ > │1 0 1 0 1│1 1 0 1│ > │1 0 1 1 1│1 1 1 1│ > │1 0 1 1 0│1 1 1 0│ > │1 0 0 1 0│1 0 1 0│ > │1 0 0 1 1│1 0 1 1│ > │1 0 0 0 1│1 0 0 1│ > │1 0 0 0 0│1 0 0 0│ > └─────────┴───────┘ > > > On Sun, Nov 17, 2013 at 2:53 PM, Bo Jacoby <[email protected]> wrote: > > > This program for graycode may be simpler? > > > > bin=.2 2 2 2&#: > > gray=.[:-.[:(=_1|.!.0"1])bin > > bin i.16 > > 0 0 0 0 > > 0 0 0 1 > > 0 0 1 0 > > 0 0 1 1 > > 0 1 0 0 > > 0 1 0 1 > > 0 1 1 0 > > 0 1 1 1 > > 1 0 0 0 > > 1 0 0 1 > > 1 0 1 0 > > 1 0 1 1 > > 1 1 0 0 > > 1 1 0 1 > > 1 1 1 0 > > 1 1 1 1 > > gray i.16 > > 0 0 0 0 > > 0 0 0 1 > > 0 0 1 1 > > 0 0 1 0 > > 0 1 1 0 > > 0 1 1 1 > > 0 1 0 1 > > 0 1 0 0 > > 1 1 0 0 > > 1 1 0 1 > > 1 1 1 1 > > 1 1 1 0 > > 1 0 1 0 > > 1 0 1 1 > > 1 0 0 1 > > 1 0 0 0 > > > > > > > > > > Den 19:40 søndag den 17. november 2013 skrev Jose Mario Quintana < > > [email protected]>: > > > > Thanks for the assertion and the correction. I knew it was named after a > > >person, hence the upper case G, but I am one of those that reads and > > writes > > >phonetically (if you know what I mean) and I could not see (hear) the > > >difference between Gray and grey. > > > > > >On Sun, Nov 17, 2013 at 12:06 PM, Henry Rich <[email protected]> > > wrote: > > > > > >> Oh - and it's Gray code, not Grey. It's named not because you don't > > have > > >> black-to-white transitions on more than one bit at a time; it's named > > for > > >> Frank Gray. > > >> > > >> > > >> Henry Rich > > >> > > >> On 11/17/2013 11:24 AM, Jose Mario Quintana wrote: > > >> > > >>> My understanding is that Grey codes encode numbers in such a way > that > > the > > >>> binary representation of consecutive numbers (including the last and > > first > > >>> couple) in the sequence can be produced, one from the other, by > > flipping > > >>> only one bit. > > >>> For example, the binary representation of a four bit Grey sequence, of > > 2^4 > > >>> numbers, and the flipping bit to produce the next number follows, > > >>> > > >>> o=. @: > > >>> ( Grey=. (xor f. <. o -:) o i. o (2&^)) ( xor=. 22 b. ) > > >>> (22 b. <.@:-:)@:i.@:(2&^) 22 b. > > >>> > > >>> (#: ; (2 #: o (xor/\) ]) o (, {.)) o Grey 4 > > >>> ┌───────┬───────┐ > > >>> │0 0 0 0│0 0 0 1│ > > >>> │0 0 0 1│0 0 1 0│ > > >>> │0 0 1 1│0 0 0 1│ > > >>> │0 0 1 0│0 1 0 0│ > > >>> │0 1 1 0│0 0 0 1│ > > >>> │0 1 1 1│0 0 1 0│ > > >>> │0 1 0 1│0 0 0 1│ > > >>> │0 1 0 0│1 0 0 0│ > > >>> │1 1 0 0│0 0 0 1│ > > >>> │1 1 0 1│0 0 1 0│ > > >>> │1 1 1 1│0 0 0 1│ > > >>> │1 1 1 0│0 1 0 0│ > > >>> │1 0 1 0│0 0 0 1│ > > >>> │1 0 1 1│0 0 1 0│ > > >>> │1 0 0 1│0 0 0 1│ > > >>> │1 0 0 0│1 0 0 0│ > > >>> └───────┴───────┘ > > >>> > > >>> However, flipping as many as three bits are sometimes required for > the > > >>> referred sequence, > > >>> > > >>> T=. 0 8 12 14 15 13 10 11 9 4 6 7 5 2 3 1 > > >>> > > >>> (#: ; (2 #: o (xor/\) ]) o (, {.)) T > > >>> ┌───────┬───────┐ > > >>> │0 0 0 0│1 0 0 0│ > > >>> │1 0 0 0│0 1 0 0│ > > >>> │1 1 0 0│0 0 1 0│ > > >>> │1 1 1 0│0 0 0 1│ > > >>> │1 1 1 1│0 0 1 0│ > > >>> │1 1 0 1│0 1 1 1│ > > >>> │1 0 1 0│0 0 0 1│ > > >>> │1 0 1 1│0 0 1 0│ > > >>> │1 0 0 1│1 1 0 1│ > > >>> │0 1 0 0│0 0 1 0│ > > >>> │0 1 1 0│0 0 0 1│ > > >>> │0 1 1 1│0 0 1 0│ > > >>> │0 1 0 1│0 1 1 1│ > > >>> │0 0 1 0│0 0 0 1│ > > >>> │0 0 1 1│0 0 1 0│ > > >>> │0 0 0 1│0 0 0 1│ > > >>> └───────┴───────┘ > > >>> > > >>> Am I missing something? > > >>> > > >>> > > >>> > > >>> On Fri, Nov 15, 2013 at 2:07 PM, R.E. Boss <[email protected]> wrote: > > >>> > > >>> Actually, it IS a (4D binary reflected) Gray code. > > >>>> > > >>>> > > >>>> R.E. Boss > > >>>> > > >>>> (Add your info to > > http://www.jsoftware.com/jwiki/Community/Demographics) > > >>>> > > >>>> > > >>>> -----Original Message----- > > >>>>> From: [email protected] > [mailto:programming- > > >>>>> [email protected]] On Behalf Of Devon McCormick > > >>>>> Sent: vrijdag 15 november 2013 19:33 > > >>>>> To: J-programming forum > > >>>>> Subject: Re: [Jprogramming] Sets > > >>>>> > > >>>>> These look like Gray codes. > > >>>>> > > >>>>> On Nov 14, 2013 10:04 PM, "Raul Miller" <[email protected]> > > wrote: > > >>>>> > > >>>>>> > > >>>>>> Easy enough to add. > > >>>>>> > > >>>>>> It's an interesting progression though: > > >>>>>> > > >>>>>> #:/:&> (<@#~ 2 #:@i.@^ #)&.> set 2;'b';1;'a' > > >>>>>> 0 0 0 0 > > >>>>>> 1 0 0 0 > > >>>>>> 1 1 0 0 > > >>>>>> 1 1 1 0 > > >>>>>> 1 1 1 1 > > >>>>>> 1 1 0 1 > > >>>>>> 1 0 1 0 > > >>>>>> 1 0 1 1 > > >>>>>> 1 0 0 1 > > >>>>>> 0 1 0 0 > > >>>>>> 0 1 1 0 > > >>>>>> 0 1 1 1 > > >>>>>> 0 1 0 1 > > >>>>>> 0 0 1 0 > > >>>>>> 0 0 1 1 > > >>>>>> 0 0 0 1 > > >>>>>> > > >>>>>> -- > > >>>>>> Raul > > >>>>>> > > >>>>>> On Thu, Nov 14, 2013 at 6:06 PM, km <[email protected]> wrote: > > >>>>>> > > >>>>>>> Cool; needs a sort. --Kip > > >>>>>>> > > >>>>>>> > > >>>>>>> psr=: (<@#~ 2 #:@i.@^ #)&.> NB. Raul's > > >>>>>>> psr set 0;1 > > >>>>>>> +----------------+ > > >>>>>>> |++---+---+-----+| > > >>>>>>> |||+-+|+-+|+-+-+|| > > >>>>>>> ||||1|||0|||0|1||| > > >>>>>>> |||+-+|+-+|+-+-+|| > > >>>>>>> |++---+---+-----+| > > >>>>>>> +----------------+ > > >>>>>>> ps set 0;1 NB. list inside box is sorted > > >>>>>>> +----------------+ > > >>>>>>> |++---+-----+---+| > > >>>>>>> |||+-+|+-+-+|+-+|| > > >>>>>>> ||||0|||0|1|||1||| > > >>>>>>> |||+-+|+-+-+|+-+|| > > >>>>>>> |++---+-----+---+| > > >>>>>>> +----------------+ > > >>>>>>> > > >>>>>>> Sent from my iPad > > >>>>>>> > > >>>>>>> On Nov 14, 2013, at 3:17 PM, Raul Miller > <[email protected]> > > >>>>>>>> > > >>>>>>> wrote: > > >>>>> > > >>>>>> > > >>>>>>>> Derived from ps at http://rosettacode.org/wiki/Power_set#J > > >>>>>>>> > > >>>>>>>> ps=: (<@#~ 2 #:@i.@^ #)&.> > > >>>>>>>> > > >>>>>>>> -- > > >>>>>>>> Raul > > >>>>>>>> > > >>>>>>>> > > >>>>>>>> On Thu, Nov 14, 2013 at 3:17 PM, km <[email protected]> > wrote: > > >>>>>>>>> Here is my latest attempt at sets in J. Would anyone care to > > write > > >>>>>>>>> > > >>>>>>>> a > > >>>> > > >>>>> verb ps (power set) such that ps y is the set of all subsets of set > > y? > > >>>>> It's called the power set in part because when a set has n elements > > >>>>> its > > >>>>> power set has 2^n elements. --Kip Murray > > >>>>> > > >>>>>> > > >>>>>>>>> NB. A set is a box with a sorted list of boxes inside. > > >>>>>>>>> NB. An element is the contents of a box in the list. > > >>>>>>>>> NB. A -: B tests whether set A is set B. > > >>>>>>>>> > > >>>>>>>>> set =: [: < [: /:~ ~. NB. create set from list of boxes > > >>>>>>>>> > > >>>>>>>>> NB. The list may have duplicates but the set has none. > > >>>>>>>>> > > >>>>>>>>> EE =: <$0 NB. empty set, same as Ace a: > > >>>>>>>>> > > >>>>>>>>> eo =: <@[ e. >@] NB. test whether x is an element of y > > >>>>>>>>> > > >>>>>>>>> uu =: [: set ,&> NB. union > > >>>>>>>>> > > >>>>>>>>> mm =: [: < -.&> NB. minus > > >>>>>>>>> > > >>>>>>>>> sd =: mm uu mm~ NB. symmetric difference > > >>>>>>>>> > > >>>>>>>>> cp =: uu mm sd NB. common part (intersection) > > >>>>>>>>> > > >>>>>>>>> ss =: uu -: ] NB. test whether x is a subset of y > > >>>>>>>>> > > >>>>>>>>> (set 1;2;3;3) -: set 3;1;2 > > >>>>>>>>> 1 > > >>>>>>>>> > > >>>>>>>>> ]A =: set 2;'b';1;'a' > > >>>>>>>>> +---------+ > > >>>>>>>>> |+-+-+-+-+| > > >>>>>>>>> ||1|2|a|b|| > > >>>>>>>>> |+-+-+-+-+| > > >>>>>>>>> +---------+ > > >>>>>>>>> > > >>>>>>>>> ]B =: set 'b';'a';4;3;'a' > > >>>>>>>>> +---------+ > > >>>>>>>>> |+-+-+-+-+| > > >>>>>>>>> ||3|4|a|b|| > > >>>>>>>>> |+-+-+-+-+| > > >>>>>>>>> +---------+ > > >>>>>>>>> > > >>>>>>>>> A uu B > > >>>>>>>>> +-------------+ > > >>>>>>>>> |+-+-+-+-+-+-+| > > >>>>>>>>> ||1|2|3|4|a|b|| > > >>>>>>>>> |+-+-+-+-+-+-+| > > >>>>>>>>> +-------------+ > > >>>>>>>>> > > >>>>>>>>> A sd B > > >>>>>>>>> +---------+ > > >>>>>>>>> |+-+-+-+-+| > > >>>>>>>>> ||1|2|3|4|| > > >>>>>>>>> |+-+-+-+-+| > > >>>>>>>>> +---------+ > > >>>>>>>>> > > >>>>>>>>> A cp B > > >>>>>>>>> +-----+ > > >>>>>>>>> |+-+-+| > > >>>>>>>>> ||a|b|| > > >>>>>>>>> |+-+-+| > > >>>>>>>>> +-----+ > > >>>>>>>>> > > >>>>>>>>> NB. Below is the set of all subsets of set 0;1 > > >>>>>>>>> > > >>>>>>>>> set EE;(set <0);(set <1);<set 0;1 > > >>>>>>>>> +------------------------+ > > >>>>>>>>> |+--+-----+-------+-----+| > > >>>>>>>>> ||++|+---+|+-----+|+---+|| > > >>>>>>>>> ||||||+-+|||+-+-+|||+-+||| > > >>>>>>>>> ||++|||0|||||0|1|||||1|||| > > >>>>>>>>> || ||+-+|||+-+-+|||+-+||| > > >>>>>>>>> || |+---+|+-----+|+---+|| > > >>>>>>>>> |+--+-----+-------+-----+| > > >>>>>>>>> +------------------------+ > > >>>>>>>>> > > >>>>>>>>> Sent from my iPad > > >>>>>>>>> > > >>>>>>>>> ------------------------------------------------------------ > > >>>> ---------- > > >>>> > > >>>>> For information about J forums see > > >>>>>>>>> > > >>>>>>>> http://www.jsoftware.com/forums.htm > > > > > >>>>> > > >>>>>> > > >>>>>>>> ------------------------------------------------------------ > > >>>> ---------- > > >>>> > > >>>>> For information about J forums see > > >>>>>>>> > > >>>>>>> http://www.jsoftware.com/forums.htm > > >>>>> > > >>>>>> > > >>>>>>> ------------------------------------------------------------ > > >>>> ---------- > > >>>> > > >>>>> For information about J forums see > > >>>>>>> > > >>>>>> http://www.jsoftware.com/forums.htm > > >>>>> > > >>>>>> > > ---------------------------------------------------------------------- > > >>>>>> For information about J forums see > > >>>>>> > > >>>>> http://www.jsoftware.com/forums.htm > > >>>>> > > ---------------------------------------------------------------------- > > >>>>> For information about J forums see > > http://www.jsoftware.com/forums.htm > > >>>>> > > >>>> > > >>>> ---------------------------------------------------------------------- > > >>>> For information about J forums see > > http://www.jsoftware.com/forums.htm > > >>>> > > >>>> > > ---------------------------------------------------------------------- > > >>> For information about J forums see > http://www.jsoftware.com/forums.htm > > >>> > > >>> ---------------------------------------------------------------------- > > >> For information about J forums see > http://www.jsoftware.com/forums.htm > > >> > > >---------------------------------------------------------------------- > > >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
