grade on nested arrays

If we don't know about 'em, we can't fix 'em.

grade on nested arrays

PostPosted by drab » Fri Apr 14, 2017 5:53 am

this works fine
⍋ ⎕← ⍕⊃ 'dog' 'cat' 'bird'
dog
cat
bird
3 2 1

and even this works fine
⍋ ⎕← ⊃ 'dog' 'cat' 'bird'
dog
cat
bird
3 2 1

but this is wrong
⍋ ⎕← 'dog' 'cat' 'bird'
dog cat bird
2 1 3


In general grade does not currently work right on a nested array.

It could give a error, but that's not very useful.

A consistently good and simple and quite useful answer would be

⍋ nested ←→ ⍋⍕⊃ nested
drab
 
Posts: 315
Joined: Thu Oct 09, 2014 6:23 am

Re: grade on nested arrays

PostPosted by forummaster » Fri Apr 14, 2017 6:21 pm

drab wrote:this works fine
⍋ ⎕← ⍕⊃ 'dog' 'cat' 'bird'
dog
cat
bird
3 2 1

and even this works fine
⍋ ⎕← ⊃ 'dog' 'cat' 'bird'
dog
cat
bird
3 2 1

but this is wrong
⍋ ⎕← 'dog' 'cat' 'bird'
dog cat bird
2 1 3


In general grade does not currently work right on a nested array.

It could give a error, but that's not very useful.

A consistently good and simple and quite useful answer would be

⍋ nested ←→ ⍋⍕⊃ nested
Grade works fine on nested and heterogeneous arrays when you view it in a larger context.

Because a nested array can contain anything in each element, we need a way to compare arbitrary items. Such a way is as follows:

1. Distinguish by type: Numbers < Characters < Nested/Heterogeneous
2. Within same type (as above), distinguish by rank with smaller rank < larger rank
3. Within same rank values, distinguish by shape with lexicographic ordering of shape
4. Within same rank/shape, distinguish by value in the usual way. Note that HC numbers aren't comparable, so they signal a DOMAIN ERROR.

I'd be happy to consider a different set of rules keeping in mind Occam's Razor -- that is, a preference is given to ones with the fewest exceptions.
forummaster
 
Posts: 567
Joined: Wed Jan 23, 2013 1:00 pm

Re: grade on nested arrays

PostPosted by drab » Sun Apr 16, 2017 5:52 pm

This is only 1 rule compared to your 4 rules

⍋ nested ←→ ⍋⍕⊃ nested

And it makes my example work as I expect.
drab
 
Posts: 315
Joined: Thu Oct 09, 2014 6:23 am

Re: grade on nested arrays

PostPosted by forummaster » Mon Apr 17, 2017 11:24 am

drab wrote:This is only 1 rule compared to your 4 rules

⍋ nested ←→ ⍋⍕⊃ nested

And it makes my example work as I expect.

I like your idea, but it misses some cases:

      ⍋'0' 0
2 1
⍋0 '0'
1 2
⍋⍕⊃'0' 0
2 1 3

Also ⍋⍕⊃(2 3⍴⍳6)(2 3 4⍴'a') signals a RANK ERROR on the Disclose. This isn't as bad as it might seem, as I've been thinking about extending Disclose to a Conforming Disclose where the shape vectors of short rank items are padded with leading 1s so they are all of the same rank. This behavior is needed in the Rank operator, and Dyalog has already implemented this change.
forummaster
 
Posts: 567
Joined: Wed Jan 23, 2013 1:00 pm

Re: grade on nested arrays

PostPosted by drab » Mon Apr 17, 2017 11:52 am

My suggestion was for nested only.

But you're right. It would still miss some odd cases.
drab
 
Posts: 315
Joined: Thu Oct 09, 2014 6:23 am

Re: grade on nested arrays

PostPosted by forummaster » Mon Apr 17, 2017 2:17 pm

drab wrote:My suggestion was for nested only.

But you're right. It would still miss some odd cases.

Nested and Heterogeneous are really two sides of the same coin. If I had it to over again, I might well not use separate types for those two objects. In fact, in the original NARS, they were one type I called NOSH for Nested Or Simple Heterogeneous.

In any case ⊂'0' 0 is nested and misbehaves as in
      ⍋⍕⊃⊂'0' 0
2 1 3
forummaster
 
Posts: 567
Joined: Wed Jan 23, 2013 1:00 pm


Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 1 guest

cron