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