Re: [Jprogramming] String sort, possible bug

2020-03-13 Thread Raul Miller
Hmm... you're right.

And, simpler,

lessThan=: (~:/ * 0 1 -: /:)@,&<&,

That said, part of this is also that strings are implied to be rank 1
and not in-and-of themselves boxed, so, maybe:

lessThan=: (~:/ * 0 1 -: /:)@,&<&(,"1 L:0)

Thanks,

-- 
Raul



On Fri, Mar 13, 2020 at 12:40 PM Henry Rich  wrote:
>
> grade would be faster than sort here I expect.
>
> Henry Rich
>
> On 3/13/2020 12:25 PM, Raul Miller wrote:
> > That's really a naming thing. It's testing for less than or equals.
> >
> > Your original version also had this character:
> >
> > 'test' ({.@:sort -: {.)@:; 'test'
> > 1
> >
> > But, yes, you can suppress the equality part with a further test.
> >
> > Thanks,
> >
>
>
> --
> This email has been checked for viruses by AVG.
> https://www.avg.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


Re: [Jprogramming] String sort, possible bug

2020-03-13 Thread Henry Rich

grade would be faster than sort here I expect.

Henry Rich

On 3/13/2020 12:25 PM, Raul Miller wrote:

That's really a naming thing. It's testing for less than or equals.

Your original version also had this character:

'test' ({.@:sort -: {.)@:; 'test'
1

But, yes, you can suppress the equality part with a further test.

Thanks,




--
This email has been checked for viruses by AVG.
https://www.avg.com

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


Re: [Jprogramming] String sort, possible bug

2020-03-13 Thread Raul Miller
That's really a naming thing. It's testing for less than or equals.

Your original version also had this character:

   'test' ({.@:sort -: {.)@:; 'test'
1

But, yes, you can suppress the equality part with a further test.

Thanks,

-- 
Raul

On Fri, Mar 13, 2020 at 12:15 PM 'Jon Hough' via Programming
 wrote:
>
>  Thanks, that's nicer.
>
> But even that is not quite correct.
>
> 'z' lessThan 'z'
> 1
>
> perhaps
> lt=: (({.@:sort -: {.) *. ({.~:{:))@,&<&,
>
>  On Saturday, March 14, 2020, 12:59:15 AM GMT+9, Raul Miller 
>  wrote:
>
>  Maybe
>   lessThan=: ({.@:sort -: {.)@,&<&,
>
> Thanks,
>
> --
> Raul
>
> On Fri, Mar 13, 2020 at 11:41 AM 'Jon Hough' via Programming
>  wrote:
> >
> >  Thanks,
> >
> > you are, of course, correct, and I should have thought about it a bit more. 
> > I am trying to make string comparison verbs
> > and this will make the solution a little more ugly.
> >
> >  lessThan=: ({.@:sort -: {.)@:;
> >  'abc' lessThan 'def'
> > 1
> >
> >
> >  'z' lessThan 'ab'
> > 1
> >  Needs a little more work for literals with no rank.
> >  ]`(1&$)@.((''&-:)@:$) 'z'
> >
> > As far as I can see there is no string comparison in the J stdlib.
> >
> > Thanks,
> > Jon
> >
> >  On Friday, March 13, 2020, 03:12:48 PM GMT+9, Thomas McGuire 
> >  wrote:
> >
> >  The first 2 of the list have no rank.
> >
> > $ each words
> >
> >  $ each words
> > ┌┬┬─┬─┬─┬─┐
> > │││3│3│4│4│
> > └┴┴─┴─┴─┴─┘
> > words =: (1$'a');(1$'z');'zza';'abc';'zabc';’abbb'
> >
> > $ each words
> > ┌─┬─┬─┬─┬─┬─┐
> > │1│1│3│3│4│4│
> > └─┴─┴─┴─┴─┴─┘
> >  sort words
> > ┌─┬┬───┬─┬┬───┐
> > │a│abbb│abc│z│zabc│zza│
> > └─┴┴───┴─┴┴───┘
> > Above if I give everything a 1 dimensional rank it works as you would 
> > expect.
> >
> > Single letter in quotes is not a string
> >
> > It happens with single numbers as well:
> >  b =:1
> > $b
> >
> >
> > No output back
> >
> > Tom McGuire
> >
> > > On Mar 13, 2020, at 1:19 AM, 'Jon Hough' via Programming 
> > >  wrote:
> > >
> > > words =: 'a';'z';'zza';'abc';'zabc';'abbb'
> >
> > --
> > 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] String sort, possible bug

2020-03-13 Thread 'Jon Hough' via Programming
 Thanks, that's nicer.

But even that is not quite correct. 

'z' lessThan 'z'
1

perhaps 
lt=: (({.@:sort -: {.) *. ({.~:{:))@,&<&,

 On Saturday, March 14, 2020, 12:59:15 AM GMT+9, Raul Miller 
 wrote:  
 
 Maybe
  lessThan=: ({.@:sort -: {.)@,&<&,

Thanks,

-- 
Raul

On Fri, Mar 13, 2020 at 11:41 AM 'Jon Hough' via Programming
 wrote:
>
>  Thanks,
>
> you are, of course, correct, and I should have thought about it a bit more. I 
> am trying to make string comparison verbs
> and this will make the solution a little more ugly.
>
>  lessThan=: ({.@:sort -: {.)@:;
>  'abc' lessThan 'def'
> 1
>
>
>  'z' lessThan 'ab'
> 1
>  Needs a little more work for literals with no rank.
>  ]`(1&$)@.((''&-:)@:$) 'z'
>
> As far as I can see there is no string comparison in the J stdlib.
>
> Thanks,
> Jon
>
>      On Friday, March 13, 2020, 03:12:48 PM GMT+9, Thomas McGuire 
> wrote:
>
>  The first 2 of the list have no rank.
>
> $ each words
>
>  $ each words
> ┌┬┬─┬─┬─┬─┐
> │││3│3│4│4│
> └┴┴─┴─┴─┴─┘
> words =: (1$'a');(1$'z');'zza';'abc';'zabc';’abbb'
>
> $ each words
> ┌─┬─┬─┬─┬─┬─┐
> │1│1│3│3│4│4│
> └─┴─┴─┴─┴─┴─┘
>  sort words
> ┌─┬┬───┬─┬┬───┐
> │a│abbb│abc│z│zabc│zza│
> └─┴┴───┴─┴┴───┘
> Above if I give everything a 1 dimensional rank it works as you would expect.
>
> Single letter in quotes is not a string
>
> It happens with single numbers as well:
>  b =:1
> $b
>
>
> No output back
>
> Tom McGuire
>
> > On Mar 13, 2020, at 1:19 AM, 'Jon Hough' via Programming 
> >  wrote:
> >
> > words =: 'a';'z';'zza';'abc';'zabc';'abbb'
>
> --
> 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] String sort, possible bug

2020-03-13 Thread Raul Miller
Maybe
   lessThan=: ({.@:sort -: {.)@,&<&,

Thanks,

-- 
Raul

On Fri, Mar 13, 2020 at 11:41 AM 'Jon Hough' via Programming
 wrote:
>
>  Thanks,
>
> you are, of course, correct, and I should have thought about it a bit more. I 
> am trying to make string comparison verbs
> and this will make the solution a little more ugly.
>
>  lessThan=: ({.@:sort -: {.)@:;
>  'abc' lessThan 'def'
> 1
>
>
>  'z' lessThan 'ab'
> 1
>  Needs a little more work for literals with no rank.
>  ]`(1&$)@.((''&-:)@:$) 'z'
>
> As far as I can see there is no string comparison in the J stdlib.
>
> Thanks,
> Jon
>
>  On Friday, March 13, 2020, 03:12:48 PM GMT+9, Thomas McGuire 
>  wrote:
>
>  The first 2 of the list have no rank.
>
> $ each words
>
>   $ each words
> ┌┬┬─┬─┬─┬─┐
> │││3│3│4│4│
> └┴┴─┴─┴─┴─┘
> words =: (1$'a');(1$'z');'zza';'abc';'zabc';’abbb'
>
> $ each words
> ┌─┬─┬─┬─┬─┬─┐
> │1│1│3│3│4│4│
> └─┴─┴─┴─┴─┴─┘
>   sort words
> ┌─┬┬───┬─┬┬───┐
> │a│abbb│abc│z│zabc│zza│
> └─┴┴───┴─┴┴───┘
> Above if I give everything a 1 dimensional rank it works as you would expect.
>
> Single letter in quotes is not a string
>
> It happens with single numbers as well:
>   b =:1
> $b
>
>
> No output back
>
> Tom McGuire
>
> > On Mar 13, 2020, at 1:19 AM, 'Jon Hough' via Programming 
> >  wrote:
> >
> > words =: 'a';'z';'zza';'abc';'zabc';'abbb'
>
> --
> 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] Iteration

2020-03-13 Thread Hauke Rehr

If that’s what was intended, I’d rather write
;/6 (? $~) 55
(adhering to the DRY principle).

Am 13.03.20 um 16:22 schrieb Raul Miller:

Here's another approach:

;/6?255#55

Here, I decided that "extended fifty times" really meant that you
wanted another 50 copies of that expression (extended linearly). But
of course you can tweak the numbers.

FYI,



--
--
mail written using NEO
neo-layout.org

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


Re: [Jprogramming] String sort, possible bug

2020-03-13 Thread 'Jon Hough' via Programming
 Thanks,

you are, of course, correct, and I should have thought about it a bit more. I 
am trying to make string comparison verbs
and this will make the solution a little more ugly.

 lessThan=: ({.@:sort -: {.)@:; 
 'abc' lessThan 'def'
1


 'z' lessThan 'ab'
1
 Needs a little more work for literals with no rank.
 ]`(1&$)@.((''&-:)@:$) 'z'

As far as I can see there is no string comparison in the J stdlib.

Thanks,
Jon

 On Friday, March 13, 2020, 03:12:48 PM GMT+9, Thomas McGuire 
 wrote:  
 
 The first 2 of the list have no rank. 

$ each words

  $ each words
┌┬┬─┬─┬─┬─┐
│││3│3│4│4│
└┴┴─┴─┴─┴─┘
words =: (1$'a');(1$'z');'zza';'abc';'zabc';’abbb'

$ each words
┌─┬─┬─┬─┬─┬─┐
│1│1│3│3│4│4│
└─┴─┴─┴─┴─┴─┘
  sort words
┌─┬┬───┬─┬┬───┐
│a│abbb│abc│z│zabc│zza│
└─┴┴───┴─┴┴───┘
Above if I give everything a 1 dimensional rank it works as you would expect.

Single letter in quotes is not a string

It happens with single numbers as well:
  b =:1
$b


No output back

Tom McGuire

> On Mar 13, 2020, at 1:19 AM, 'Jon Hough' via Programming 
>  wrote:
> 
> words =: 'a';'z';'zza';'abc';'zabc';'abbb'

--
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] modifiers

2020-03-13 Thread Henry Rich

I think I agree.

My vote would be that 'train' refers to any sequence of ARs and that 
when `:6 said 'train of individual verbs' it meant to say 'the (possibly 
derived) words created by executing the train of the (possibly derived) 
words represented by each AR'.


I would say that (<,'"') is kosher and (<'"') not, already, based on 
this interpretation of what Ye Dic meant.  The implementation is 
permissive in some cases.


Henry Rich

On 3/12/2020 11:21 PM, Jose Mario Quintana wrote:

because the long sequence of ARs is not a valid AR.

Certainly, the purpose of posing those questions was to find out where the
permissiveness breaking point would be.  This is what, I think, I have
learned regarding the tie, train, and (left) agenda arguments in J (as
described or might be described by the official documentation):  lists of
ARs of verbs are kosher, lists of ARs might become kosher; anything else is
almost surely not kosher.  Therefore, these are not kosher,

(<'"')
┌─┐
│"│
└─┘

(<'"') (`:6)
"
(<'"') (@.0)
"

but these might become kosher,

(<,'"')
┌─┐
│"│
└─┘

(<,'"') (`:6)
"
(<,'"') (@.0)
"

these are not kosher,

((<'"') ,~ (<;:'u@:v-v@:u'))
┌─┬─┐
│┌─┬──┬─┬─┬─┬──┬─┐│"│
││u│@:│v│-│v│@:│u││ │
│└─┴──┴─┴─┴─┴──┴─┘│ │
└─┴─┘

((<'"') ,~ (<;:'u@:v-v@:u')) (`:6)
(u@:v - v@:u)"
((<'"') ,~ (<;:'u@:v-v@:u')) (@.0)
u@:v - v@:u

but these might become kosher,

   (<(<,'4'),<(<(<,'3'),<(<(<'@:'),<<;._1 ' u v'),(<,'-'),<(<'@:'),<<;._1 '
v u'),<,'"')
┌─┐
│┌─┬─┐│
││4│┌─┬─┐││
││ ││┌─┬─┐│"│││
││ │││3│┌──┬─┬──┐││ │││
││ │││ ││┌──┬─┐│-│┌──┬─┐│││ │││
││ │││ │││@:│┌─┬─┐││ ││@:│┌─┬─┐ │││
││ │││ │││  ││u│v│││ ││  ││v│u│ │││
││ │││ │││  │└─┴─┘││ ││  │└─┴─┘ │││
││ │││ ││└──┴─┘│ │└──┴─┘│││ │││
││ │││ │└──┴─┴──┘││ │││
││ ││└─┴─┘│ │││
││ │└─┴─┘││
│└─┴─┘│
└─┘
(<(<,'4'),<(<(<,'3'),<(<(<'@:'),<<;._1 ' u v'),(<,'-'),<(<'@:'),<<;._1 '
v u'),<,'"')(`:6)
(u@:v - v@:u)"
(<(<,'4'),<(<(<,'3'),<(<(<'@:'),<<;._1 ' u v'),(<,'-'),<(<'@:'),<<;._1 '
v u'),<,'"')(@.0)
(u@:v - v@:u)"

There would tedious extra work involved when one wants to be kosher but it
is doable.

So far so good?


On Wed, Mar 11, 2020 at 8:58 PM Henry Rich  wrote:

I would object to

   ((<'"') ,~ (<;:'u@:v-v@:u')) (`:6)

because the long sequence of ARs is not a valid AR.  This seems like an
interpreter artifact.

The result of 5!:2 is not germane here, as it is not an AR.  Your
examples using it also seem to be interpreter artifacts to me.

Henry Rich

On 3/11/2020 8:22 PM, Jose Mario Quintana wrote:

Of course the fact that m@.n allows certain forms does not imply that
m@.v would support similar forms.

Of course.


I don't see anything to object to here.

Great!  This means tacit adverbs functioning as parameterized macros

are,

or might be eventually, legitimized.

   There are gerunds and

adverbs,

producing trains that evaluate properly.

Right, the trains evaluate properly; even though the list (;:'@:-"')
includes ARs of conjunctions (it is not my intention at all to argue

with a

/mufti/ of J, I am just accentuating).


By The Wise I mean the /ulama/ of J (neminem nominabo, genus hominum
significasse contentus)  You know who you are.

Train (`:6) can also evaluate properly forms associated with the
corresponding agenda (m@.n) evaluation, mutatis mutandis; exempli

gratia,

 ((<'"') ,~ (<;:'u@:v-v@:u'))
┌─┬─┐
│┌─┬──┬─┬─┬─┬──┬─┐│"│
││u│@:│v│-│v│@:│u││ │
│└─┴──┴─┴─┴─┴──┴─┘│ │
└─┴─┘

 ((<'"') ,~ (<;:'u@:v-v@:u')) (`:6)
(u@:v - v@:u)"

Do the /ulama/ of J (et alli) disapprove?

By the way, some boxed representations belong to this class of forms,

 t=. (u@:v - v@:u)"

 (5!:2<'t')
┌─┬─┐
│┌┬─┬┐│"│
││┌─┬──┬─┐│-│┌─┬──┬─┐││ │
│││u│@:│v││ ││v│@:│u│││ │
││└─┴──┴─┘│ │└─┴──┴─┘││ │
│└┴─┴┘│ │
└─┴─┘
 (5!:2<'t') (`:6)
(u@:v - v@:u)"

but not all of them,

 t=. "1

 (5!:2<'t')
┌─┬─┐
│"│1│
└─┴─┘

 (5!:2<'t') (`:6)
|domain error
|   (5!:2<'t')(`:6)

The issue here is the missing (in the evaluation sense) AR of 1,

 (<,'"'),<<(,'0');1
┌─┬───┐
│"│┌─┐│
│ ││┌─┬─┐││
│ │││0│1│││
│ ││└─┴─┘││
│ │└─┘│
└─┴───┘
 ((<,'"'),<<(,'0');1) (`:6)
"1


On Tue, Mar 10, 2020 at 11:49 PM Henry Rich 

wrote:

I don't see anything to object to here.  There are gerunds and adverbs,
producing trains that evaluate properly.


By The Wise I mean the /ulama/ of J (neminem nominabo, genus hominum
significasse contentus)  You know who you are.

Henry Rich

On 3/10/2020 11:34 PM, Jose Mario Quintana wrote:

I don't think it's illegal.  The spec 

Re: [Jprogramming] Iteration

2020-03-13 Thread Raul Miller
Here's another approach:

   ;/6?255#55

Here, I decided that "extended fifty times" really meant that you
wanted another 50 copies of that expression (extended linearly). But
of course you can tweak the numbers.

FYI,

-- 
Raul

On Fri, Mar 13, 2020 at 12:49 AM Skip Cave  wrote:
>
> How can I generate the following result extended 50 times, without explicit
> looping?
>
> (6?55);(6?55);(6?55);(6?55);(6?55)
>
> ┌───┬───┬─┬─┬───┐
>
> │13 4 19 43 3 52│10 1 4 46 52 11│38 12 48 50 54 45│36 54 39 35 53 50│44 1 7
> 54 11 41│
>
> └───┴───┴─┴─┴───┘
>
>
>
> Skip Cave
> Cave Consulting LLC
> --
> 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] Iteration

2020-03-13 Thread Roger Hui
0. It may be helpful to think of &.> as "each".  In fact, "each" is defined
as such by some J standard library somewhere.  Enter "each" in your J
session and see what you get.

1. See https://code.jsoftware.com/wiki/Essays/Under for examples of &. ,
including from daily life (e.g. "under anaesthetics").

2. More examples from daily life:
https://www.jsoftware.com/papers/KEIQA.htm#under1



On Fri, Mar 13, 2020 at 3:02 AM ethiejiesa via Programming <
programm...@jsoftware.com> wrote:

> Yes, those are not precise terms. I personally think of &. as embodying
> conjugation (from group theory). For monads, the analogy is often precise:
> u&.v y <-> v^:_1 u v y
>
> But you are right, the idea of conjugation is abstract enough that it is
> embodied by a dizzingly wide variety of applications: vector space base
> transformation, measure of operator non-commutivity, localization of the
> effects Rubik's cube turns, even complex conjugation etc.
>
> Anyway, specifically in th case of u&.>, since < is "box" and > is pretty
> much
> "unbox", I figured "do" and "undo" are reasonable approximations for a
> gentle
> explatation in the case at hand. Hopefully, it's helpful to Skip.
>
>
> Hauke Rehr  wrote:
> > In my opinion, “do” and “undo” is not the idea/concept of &.
> > and doesn’t get across what it actually does.
> >
> > &. is very helpful in a plethora of use cases
> > it is like transform, work in transformed space, transform back
> > (like working with conjugate matrices or in fourier space, e.g.)
> >
> >  From my personal experience (which is not much),
> > I’ve had most use of &. with v ∈ { >, |., |: }
> > but being aware of what it does for you will make
> > you find it’s useful in many more cases.
> >
> > hope this helps
> >
> >
> > Am 13.03.20 um 08:55 schrieb ethiejiesa via Programming:
> > > I'll contribute a little prose. Hopefully, it's helpful.
> > >
> > > In this particular case, notice that > transforms your list of boxes
> into a 5x6
> > > table:
> > >
> > >  > (6?55);(6?55);(6?55);(6?55);(6?55)
> > >  13 4 19 43 3 52
> > >  10 1 4 46 52 11
> > >  38 12 48 50 54 45
> > >  36 54 39 35 53 50
> > >  44 1 7 54 11 41
> > >
> > > So, we should be able to easily "reverse" the above, meaning that
> dealing with
> > > a 5x6 array is pretty much the same as dealing with 5 boxes of
> 6-arrays. Let's
> > > just keep this in mind for now, and first try to generate this 6x5
> table.
> > >
> > > The key point of ? is that it's monadic and dyadic ranks are all 0,
> meaning
> > > that it transforms an array of integers into a corresponding array of
> random
> > > numbers:
> > >
> > >  ? 50 6 $ 55
> > >  ...
> > >
> > > produces a random 50x6 array of integers each in the range i.55. This
> is not
> > > quite what we want, but we first note that it can be more idiomatically
> > > written:
> > >
> > >  50 6 ?@$ 55
> > >
> > > The utility of @ (and @:) become a lot more apparent when writing tacit
> > > expressions. In general, x u@v y is equivalent to u (x v y), applying
> u "atop"
> > > x v y, hence the mnemonic. (NB. The difference between u@v and u@:v
> is that
> > > they produce verbs of different rank.)
> > >
> > > The dyad n?m produces n random numbers without replacement. Your posed
> problem
> > > is to generate 50 such lists, so conceptually we want to *reshape* the
> > > arguments of ? into 50-lists:
> > >
> > >  (50$6) ? (50$55)
> > >
> > > but, better yet, as lots of verbs to ? will automatically reshape an
> atomic
> > > argument to the shape of the other argument, so we can abbreviate the
> above in
> > > one of two ways:
> > >
> > >  6 ? (50$55) NB. or
> > >  (50$6) ? 55
> > >
> > > In the first case, the parentheses are not necessary due to J parsing
> rules, so
> > > its more compact and idomatic to elide them
> > >
> > >  6 ? 50$55
> > >
> > > These three previous options should produce the desired random tables.
> Now,
> > > putting things together, we just want to "redo" the boxing we did in
> the
> > > beginning example:
> > >
> > >  <"1 (6 ? 50$55)
> > >
> > > Which should give the desired result. We need the
> > > parenthesis to separate the 1 from the 6, otherwise J would interpret
> this as
> > > <"1 6. Another way to break up the list lexing is like this:
> > >
> > >  <"1 [ 6 ? 50 $ 55
> > >
> > > Anyway, Hui's use of &. is even nicer. The key ideas is that u&.v
> first runs v
> > > on u's aguments and then *undoes* v on the result. The really neat
> thing is
> > > that > is a no-op on non-boxed atoms:
> > >
> > >  > 42
> > >  42
> > >
> > > So the idea is to let > be a no-op on our input array of integers,
> then let ?
> > > do it's thing, and finally *undo* > on *each* result. And since
> undoing > is
> > > simply doing <, we get what we want.
> > >
> > >  6 ?&.> 50 $ 55
> > >
> > > The "each result" part above is exactly why this form is slick. ?&.>
> has the
> > > rank of 

Re: [Jprogramming] String sort, possible bug

2020-03-13 Thread Roger Hui
Y'all may be interested in how Dyalog APL does the TAO (total array
ordering).  https://www.jsoftware.com/papers/TAOaxioms.htm  It's different
from J because the arrays are different from J.

On Fri, Mar 13, 2020 at 7:19 AM David Mitchell 
wrote:

> This is documented (see Rank sentence in the doc):
>
> https://code.jsoftware.com/wiki/Vocabulary/slashco#dyadic
>
> The order of priority for ordering-up is:
>
>  Type: numeric or empty, symbol, character (byte or unicode), and
> boxed, are
> so ordered
>  Rank: lower comes before higher
>  Values: compared after padding with fills to the same shape
>  Symbols are compared based on their symbol index, not the
> character
> lists they represent.
>
> Cheers,
> David
>
> On 3/13/2020 01:19, 'Jon Hough' via Programming wrote:
> > Consider the wrods:
> >
> > words =: 'a';'z';'zza';'abc';'zabc';'abbb'
> > sort words
> > ?
> > ???a???z???abbb???abc???zabc???zza???
> > ?
> >
> > the sorted words are not correctly (lexicographically) sorted.
> >
> > If I replace 'z' with 'z ' (space after z character)
> >   words =: 'a';'z ';'zza';'abc';'zabc';'abbb'
> > sort words
> > 
> > ???a???abbb???abc???z ???zabc???zza???
> > 
> >
> > the strings are correctly sorted.
> > It seems sort has trouble with single character strings.
> > Is this a bug, or am I misunderstanding sort with strings?
> > --
> > 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] String sort, possible bug

2020-03-13 Thread David Mitchell

This is documented (see Rank sentence in the doc):

https://code.jsoftware.com/wiki/Vocabulary/slashco#dyadic

The order of priority for ordering-up is:

Type: numeric or empty, symbol, character (byte or unicode), and boxed, are 
so ordered

Rank: lower comes before higher
Values: compared after padding with fills to the same shape
Symbols are compared based on their symbol index, not the character 
lists they represent.


Cheers,
David

On 3/13/2020 01:19, 'Jon Hough' via Programming wrote:

Consider the wrods:

words =: 'a';'z';'zza';'abc';'zabc';'abbb'
sort words
?
???a???z???abbb???abc???zabc???zza???
?

the sorted words are not correctly (lexicographically) sorted.

If I replace 'z' with 'z ' (space after z character)
  words =: 'a';'z ';'zza';'abc';'zabc';'abbb'
sort words

???a???abbb???abc???z ???zabc???zza???


the strings are correctly sorted.

It seems sort has trouble with single character strings.
Is this a bug, or am I misunderstanding sort with strings?
--
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] Iteration

2020-03-13 Thread ethiejiesa via Programming
Yes, those are not precise terms. I personally think of &. as embodying
conjugation (from group theory). For monads, the analogy is often precise:
u&.v y <-> v^:_1 u v y

But you are right, the idea of conjugation is abstract enough that it is
embodied by a dizzingly wide variety of applications: vector space base
transformation, measure of operator non-commutivity, localization of the
effects Rubik's cube turns, even complex conjugation etc.

Anyway, specifically in th case of u&.>, since < is "box" and > is pretty much
"unbox", I figured "do" and "undo" are reasonable approximations for a gentle
explatation in the case at hand. Hopefully, it's helpful to Skip.


Hauke Rehr  wrote:
> In my opinion, “do” and “undo” is not the idea/concept of &.
> and doesn’t get across what it actually does.
> 
> &. is very helpful in a plethora of use cases
> it is like transform, work in transformed space, transform back
> (like working with conjugate matrices or in fourier space, e.g.)
> 
>  From my personal experience (which is not much),
> I’ve had most use of &. with v ∈ { >, |., |: }
> but being aware of what it does for you will make
> you find it’s useful in many more cases.
> 
> hope this helps
> 
> 
> Am 13.03.20 um 08:55 schrieb ethiejiesa via Programming:
> > I'll contribute a little prose. Hopefully, it's helpful.
> > 
> > In this particular case, notice that > transforms your list of boxes into a 
> > 5x6
> > table:
> > 
> >  > (6?55);(6?55);(6?55);(6?55);(6?55)
> >  13 4 19 43 3 52
> >  10 1 4 46 52 11
> >  38 12 48 50 54 45
> >  36 54 39 35 53 50
> >  44 1 7 54 11 41
> > 
> > So, we should be able to easily "reverse" the above, meaning that dealing 
> > with
> > a 5x6 array is pretty much the same as dealing with 5 boxes of 6-arrays. 
> > Let's
> > just keep this in mind for now, and first try to generate this 6x5 table.
> > 
> > The key point of ? is that it's monadic and dyadic ranks are all 0, meaning
> > that it transforms an array of integers into a corresponding array of random
> > numbers:
> > 
> >  ? 50 6 $ 55
> >  ...
> > 
> > produces a random 50x6 array of integers each in the range i.55. This is not
> > quite what we want, but we first note that it can be more idiomatically
> > written:
> > 
> >  50 6 ?@$ 55
> > 
> > The utility of @ (and @:) become a lot more apparent when writing tacit
> > expressions. In general, x u@v y is equivalent to u (x v y), applying u 
> > "atop"
> > x v y, hence the mnemonic. (NB. The difference between u@v and u@:v is that
> > they produce verbs of different rank.)
> > 
> > The dyad n?m produces n random numbers without replacement. Your posed 
> > problem
> > is to generate 50 such lists, so conceptually we want to *reshape* the
> > arguments of ? into 50-lists:
> > 
> >  (50$6) ? (50$55)
> > 
> > but, better yet, as lots of verbs to ? will automatically reshape an atomic
> > argument to the shape of the other argument, so we can abbreviate the above 
> > in
> > one of two ways:
> > 
> >  6 ? (50$55) NB. or
> >  (50$6) ? 55
> > 
> > In the first case, the parentheses are not necessary due to J parsing 
> > rules, so
> > its more compact and idomatic to elide them
> > 
> >  6 ? 50$55
> > 
> > These three previous options should produce the desired random tables. Now,
> > putting things together, we just want to "redo" the boxing we did in the
> > beginning example:
> > 
> >  <"1 (6 ? 50$55)
> > 
> > Which should give the desired result. We need the
> > parenthesis to separate the 1 from the 6, otherwise J would interpret this 
> > as
> > <"1 6. Another way to break up the list lexing is like this:
> > 
> >  <"1 [ 6 ? 50 $ 55
> > 
> > Anyway, Hui's use of &. is even nicer. The key ideas is that u&.v first 
> > runs v
> > on u's aguments and then *undoes* v on the result. The really neat thing is
> > that > is a no-op on non-boxed atoms:
> > 
> >  > 42
> >  42
> > 
> > So the idea is to let > be a no-op on our input array of integers, then let 
> > ?
> > do it's thing, and finally *undo* > on *each* result. And since undoing > is
> > simply doing <, we get what we want.
> > 
> >  6 ?&.> 50 $ 55
> > 
> > The "each result" part above is exactly why this form is slick. ?&.> has the
> > rank of >, i.e. 0 0 0. This means that it will box each list produced by ? 
> > as
> > the integers are fed to it, which is exactly what we want in this case.
> > 
> > Very cool stuff. Rank!
> > 
> > 
> > Skip Cave  wrote:
> >> Wow! Two completely different ways to generate multiple sets of random
> >> integers. Roger used &. which I haven't really ever used or understood. I
> >> will definitely need to understand &. for the future. Devon used @, which I
> >> also haven't used very much. I need to find some practice and  training
> >> examples to work on both concepts.
> >>
> >> Skip Cave
> >> Cave Consulting LLC
> >>
> >>
> >> On Fri, Mar 13, 2020 at 12:04 AM Devon 

Re: [Jprogramming] Iteration

2020-03-13 Thread Hauke Rehr

In my opinion, “do” and “undo” is not the idea/concept of &.
and doesn’t get across what it actually does.

&. is very helpful in a plethora of use cases
it is like transform, work in transformed space, transform back
(like working with conjugate matrices or in fourier space, e.g.)

From my personal experience (which is not much),
I’ve had most use of &. with v ∈ { >, |., |: }
but being aware of what it does for you will make
you find it’s useful in many more cases.

hope this helps


Am 13.03.20 um 08:55 schrieb ethiejiesa via Programming:

I'll contribute a little prose. Hopefully, it's helpful.

In this particular case, notice that > transforms your list of boxes into a 5x6
table:

 > (6?55);(6?55);(6?55);(6?55);(6?55)
 13 4 19 43 3 52
 10 1 4 46 52 11
 38 12 48 50 54 45
 36 54 39 35 53 50
 44 1 7 54 11 41

So, we should be able to easily "reverse" the above, meaning that dealing with
a 5x6 array is pretty much the same as dealing with 5 boxes of 6-arrays. Let's
just keep this in mind for now, and first try to generate this 6x5 table.

The key point of ? is that it's monadic and dyadic ranks are all 0, meaning
that it transforms an array of integers into a corresponding array of random
numbers:

 ? 50 6 $ 55
 ...

produces a random 50x6 array of integers each in the range i.55. This is not
quite what we want, but we first note that it can be more idiomatically
written:

 50 6 ?@$ 55

The utility of @ (and @:) become a lot more apparent when writing tacit
expressions. In general, x u@v y is equivalent to u (x v y), applying u "atop"
x v y, hence the mnemonic. (NB. The difference between u@v and u@:v is that
they produce verbs of different rank.)

The dyad n?m produces n random numbers without replacement. Your posed problem
is to generate 50 such lists, so conceptually we want to *reshape* the
arguments of ? into 50-lists:

 (50$6) ? (50$55)

but, better yet, as lots of verbs to ? will automatically reshape an atomic
argument to the shape of the other argument, so we can abbreviate the above in
one of two ways:

 6 ? (50$55) NB. or
 (50$6) ? 55

In the first case, the parentheses are not necessary due to J parsing rules, so
its more compact and idomatic to elide them

 6 ? 50$55

These three previous options should produce the desired random tables. Now,
putting things together, we just want to "redo" the boxing we did in the
beginning example:

 <"1 (6 ? 50$55)

Which should give the desired result. We need the
parenthesis to separate the 1 from the 6, otherwise J would interpret this as
<"1 6. Another way to break up the list lexing is like this:

 <"1 [ 6 ? 50 $ 55

Anyway, Hui's use of &. is even nicer. The key ideas is that u&.v first runs v
on u's aguments and then *undoes* v on the result. The really neat thing is
that > is a no-op on non-boxed atoms:

 > 42
 42

So the idea is to let > be a no-op on our input array of integers, then let ?
do it's thing, and finally *undo* > on *each* result. And since undoing > is
simply doing <, we get what we want.

 6 ?&.> 50 $ 55

The "each result" part above is exactly why this form is slick. ?&.> has the
rank of >, i.e. 0 0 0. This means that it will box each list produced by ? as
the integers are fed to it, which is exactly what we want in this case.

Very cool stuff. Rank!


Skip Cave  wrote:

Wow! Two completely different ways to generate multiple sets of random
integers. Roger used &. which I haven't really ever used or understood. I
will definitely need to understand &. for the future. Devon used @, which I
also haven't used very much. I need to find some practice and  training
examples to work on both concepts.

Skip Cave
Cave Consulting LLC


On Fri, Mar 13, 2020 at 12:04 AM Devon McCormick  wrote:


6 5?@$55
Will give you a 6x5 table that is 6 independent rows of 5?55.


On Fri, Mar 13, 2020 at 12:52 AM Roger Hui 
wrote:


6 ?&.> 5 $ 55



┌┬─┬───┬─┬───┐

│47 28 45 25 8 36│22 40 23 20 11 49│15 16 42 38 4 5│50 45 38 37 13 28│42

4

36 7 23 49│



└┴─┴───┴─┴───┘


6 ?&.> 50 $ 55
...


On Thu, Mar 12, 2020 at 9:49 PM Skip Cave 

wrote:



How can I generate the following result extended 50 times, without

explicit

looping?

(6?55);(6?55);(6?55);(6?55);(6?55)






┌───┬───┬─┬─┬───┐


│13 4 19 43 3 52│10 1 4 46 52 11│38 12 48 50 54 45│36 54 39 35 53 50│44

1 7

54 11 41│






└───┴───┴─┴─┴───┘




Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For 

Re: [Jprogramming] Iteration

2020-03-13 Thread ethiejiesa via Programming
I'll contribute a little prose. Hopefully, it's helpful.

In this particular case, notice that > transforms your list of boxes into a 5x6
table:

> (6?55);(6?55);(6?55);(6?55);(6?55)
13 4 19 43 3 52
10 1 4 46 52 11
38 12 48 50 54 45
36 54 39 35 53 50
44 1 7 54 11 41

So, we should be able to easily "reverse" the above, meaning that dealing with
a 5x6 array is pretty much the same as dealing with 5 boxes of 6-arrays. Let's
just keep this in mind for now, and first try to generate this 6x5 table.

The key point of ? is that it's monadic and dyadic ranks are all 0, meaning
that it transforms an array of integers into a corresponding array of random
numbers:

? 50 6 $ 55
...

produces a random 50x6 array of integers each in the range i.55. This is not
quite what we want, but we first note that it can be more idiomatically
written:

50 6 ?@$ 55

The utility of @ (and @:) become a lot more apparent when writing tacit
expressions. In general, x u@v y is equivalent to u (x v y), applying u "atop"
x v y, hence the mnemonic. (NB. The difference between u@v and u@:v is that
they produce verbs of different rank.)

The dyad n?m produces n random numbers without replacement. Your posed problem
is to generate 50 such lists, so conceptually we want to *reshape* the
arguments of ? into 50-lists:

(50$6) ? (50$55)

but, better yet, as lots of verbs to ? will automatically reshape an atomic
argument to the shape of the other argument, so we can abbreviate the above in
one of two ways:

6 ? (50$55) NB. or
(50$6) ? 55

In the first case, the parentheses are not necessary due to J parsing rules, so
its more compact and idomatic to elide them

6 ? 50$55

These three previous options should produce the desired random tables. Now,
putting things together, we just want to "redo" the boxing we did in the
beginning example:

<"1 (6 ? 50$55)

Which should give the desired result. We need the
parenthesis to separate the 1 from the 6, otherwise J would interpret this as
<"1 6. Another way to break up the list lexing is like this:

<"1 [ 6 ? 50 $ 55

Anyway, Hui's use of &. is even nicer. The key ideas is that u&.v first runs v
on u's aguments and then *undoes* v on the result. The really neat thing is
that > is a no-op on non-boxed atoms:

> 42
42

So the idea is to let > be a no-op on our input array of integers, then let ?
do it's thing, and finally *undo* > on *each* result. And since undoing > is
simply doing <, we get what we want.

6 ?&.> 50 $ 55

The "each result" part above is exactly why this form is slick. ?&.> has the
rank of >, i.e. 0 0 0. This means that it will box each list produced by ? as
the integers are fed to it, which is exactly what we want in this case.

Very cool stuff. Rank!


Skip Cave  wrote:
> Wow! Two completely different ways to generate multiple sets of random
> integers. Roger used &. which I haven't really ever used or understood. I
> will definitely need to understand &. for the future. Devon used @, which I
> also haven't used very much. I need to find some practice and  training
> examples to work on both concepts.
> 
> Skip Cave
> Cave Consulting LLC
> 
> 
> On Fri, Mar 13, 2020 at 12:04 AM Devon McCormick  wrote:
> 
> >6 5?@$55
> > Will give you a 6x5 table that is 6 independent rows of 5?55.
> >
> >
> > On Fri, Mar 13, 2020 at 12:52 AM Roger Hui 
> > wrote:
> >
> > >6 ?&.> 5 $ 55
> > >
> > >
> > ┌┬─┬───┬─┬───┐
> > > │47 28 45 25 8 36│22 40 23 20 11 49│15 16 42 38 4 5│50 45 38 37 13 28│42
> > 4
> > > 36 7 23 49│
> > >
> > >
> > └┴─┴───┴─┴───┘
> > >
> > >6 ?&.> 50 $ 55
> > > ...
> > >
> > >
> > > On Thu, Mar 12, 2020 at 9:49 PM Skip Cave 
> > wrote:
> > >
> > > > How can I generate the following result extended 50 times, without
> > > explicit
> > > > looping?
> > > >
> > > > (6?55);(6?55);(6?55);(6?55);(6?55)
> > > >
> > > >
> > > >
> > >
> > ┌───┬───┬─┬─┬───┐
> > > >
> > > > │13 4 19 43 3 52│10 1 4 46 52 11│38 12 48 50 54 45│36 54 39 35 53 50│44
> > > 1 7
> > > > 54 11 41│
> > > >
> > > >
> > > >
> > >
> > └───┴───┴─┴─┴───┘
> > > >
> > > >
> > > >
> > > > Skip Cave
> > > > Cave Consulting LLC
> > > > --
> > > > 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
> >
> > Quantitative Consultant
> > --
> > For information about J forums 

Re: [Jprogramming] String sort, possible bug

2020-03-13 Thread Thomas McGuire
The first 2 of the list have no rank. 

$ each words

  $ each words
┌┬┬─┬─┬─┬─┐
│││3│3│4│4│
└┴┴─┴─┴─┴─┘
words =: (1$'a');(1$'z');'zza';'abc';'zabc';’abbb'

$ each words
┌─┬─┬─┬─┬─┬─┐
│1│1│3│3│4│4│
└─┴─┴─┴─┴─┴─┘
   sort words
┌─┬┬───┬─┬┬───┐
│a│abbb│abc│z│zabc│zza│
└─┴┴───┴─┴┴───┘
Above if I give everything a 1 dimensional rank it works as you would expect.

Single letter in quotes is not a string

It happens with single numbers as well:
   b =:1
$b


No output back

Tom McGuire

> On Mar 13, 2020, at 1:19 AM, 'Jon Hough' via Programming 
>  wrote:
> 
> words =: 'a';'z';'zza';'abc';'zabc';'abbb'

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