Symbols for sort idioms

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

Re: Symbols for sort idioms

Postby Bob Armstrong on Sun Nov 14, 2021 4:41 pm

Thanks for a lot of interesting presentation & discussion in the conf last week .

I was very slow in implementing ` sort in CoSy because I so wanted ` grade .

Finally , I figured out how to append iota to the list to be sorted to be carried along during the sort , built on Helmar Wodke's terse algorithm , http://cosy.com/4thCoSy/Code/CoSy/sort.f . ( It needs to be revisited because it is not order preserving for equals . )

I've found no way to get the ` grade `w/o doing the sort . If there is , please enlighten me .

So I agree ` sort should have been and be a primitive . I'm surprised the inefficiency of having to go around the grade > index ring to retrieve the sort survived the early years of APL .

I'm taking the liberty of showing the coded for ` nub and ` group which are at about line 1580 in http://cosy.com/4thCoSy/Code/CoSy/CoSy.f .

Code: Select all
| return unique items .  Like  K's  ' ?
: nubb 1p> R@ ['] where 'R ,/ R@ rho iota =i 1P> ; | bool of 1st occurances
: nubx nubb & ;    | indices of 1st occurences
: nub 1p> dup nubx at 1P> ;    | unique items .
: nnub 1p> dup nubb 0=i & at 1P> ; | redundants
 
| Group items by uniques | see Wed.Oct,20191002 | https://youtu.be/fxx9kS_seXk |
: grpib 1p> nub R@ ,/ ['] =i 'L 1P> ;    | group integer bool
: grpix grpib ['] & 'm ;        | group integer index
 
: grpcx >a> nub a> swap  ' conn 'R  ;
 
| 20191008 | ` nubgrp optimized merge . Eliminates redundant call of ' nub
: nubgrpib 1p> nub >a> R@ ,/ ['] =i 'L a> swap ,L 1P> ; | nub & group integer bool
| and uses CoSy's access to addresses using ' ix rather than just ' i@ and ' i!
| to optimally replace just the second item in the result from ' nubgrpib
: nubgrpix nubgrpib >a> 1 ix dup @ ['] & 'm swap rplc a> ;
 
: nubgrpcx >a> nub a> swap >a> ' conn 'R a> swap ,L  ;    | 20210625
| /\ | Takes list . Returns 2 item list of `( nub grp )` .
 
| ( L R  --  nub sums ,L )
: aggr nubgrpcx >a> 1th { at +/ } 'R a> dsc swap ,L ;
| aggregate ( sum ) values L by nub of R . | 20210705 |


` nub and ` group are a similar situation where you can't do the ` group w/o doing the nub . So you can save some work by having a word which returns both together .
User avatar
Bob Armstrong
 
Posts: 27
Joined: Wed Dec 23, 2009 8:41 pm
Location: 39.038681° -105.079070° 2500m

Re: Symbols for sort idioms

Postby michaelk on Sun Dec 05, 2021 3:13 am

Adam|Dyalog wrote:
michaelk wrote:Would it be possible to replace the two sort idioms ({(⊂⍋⍵)⌷⍵} and its counterpart) by symbols in a future release?


I would make monadic ∧ and ∨ be sorting primitives because they are mnemonic as simpler versions of the glyphs ⍋ and ⍒.


Great idea!
michaelk
 
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

Re: Symbols for sort idioms

Postby Phil Last on Sun Dec 05, 2021 4:07 pm

michaelk wrote:
Adam|Dyalog wrote:
michaelk wrote:Would it be possible to replace the two sort idioms ({(⊂⍋⍵)⌷⍵} and its counterpart) by symbols in a future release?


I would make monadic ∧ and ∨ be sorting primitives because they are mnemonic as simpler versions of the glyphs ⍋ and ⍒.


Great idea!

Gets my vote.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Symbols for sort idioms

Postby Bob Armstrong on Sun Dec 12, 2021 6:15 pm

I haven't used traditional APL since ` flat STSC APL+PC , having shifted to K , then to creating CoSy .

But I'm just gobsmacked that ∨ and ∧ never had monadic definition !
And I apparently never noticed !
They are naturals for sort .

Since , I don't think it's possible to get the grade without doing the sort , they should be a lot more efficient .
User avatar
Bob Armstrong
 
Posts: 27
Joined: Wed Dec 23, 2009 8:41 pm
Location: 39.038681° -105.079070° 2500m

Re: Symbols for sort idioms

Postby michaelk on Fri Aug 12, 2022 3:57 am

Is there any progress on replacing the sort idioms with symbols such as monadic ∨ and ∧, as suggested by Adam?
michaelk
 
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

Re: Symbols for sort idioms

Postby Adam|Dyalog on Fri Aug 12, 2022 4:23 am

michaelk wrote:Is there any progress on replacing the sort idioms with symbols such as monadic ∨ and ∧, as suggested by Adam?

At Dyalog '22, we'll present a proposal for a neater universal way to sort.
User avatar
Adam|Dyalog
 
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: Symbols for sort idioms

Postby michaelk on Wed Jan 04, 2023 12:00 am

Can you tell us what is proposed?
michaelk
 
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

Re: Symbols for sort idioms

Postby Adam|Dyalog on Wed Jan 04, 2023 5:55 am

D15: Filling the Core Language Gaps suggests ⍛ ("behind") be {⍺←⍵ ⋄ (⍺⍺ ⍺)⍵⍵ ⍵} and ⊇ ("select") be {(⊂⍺)⌷⍵} (and more) so that ⍋⍛⊇Y sorts Y and X⍋⍛⊇Y sorts Y by X. You can try it out with the models:
      ]get -u github.com/abrudz/primitives
#.behindQA #.behindUse #.depthQA #.depthUse #.selectQA #.selectUse #.Ö #.Ⓓ #.Ⓞ
Sort←⍋ Ⓞ Ⓓ ⍝ ⍋⍛⊇
Sort 'world'
dlorw
20 10 40 30 40 Sort 'world'
owlrd
User avatar
Adam|Dyalog
 
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: Symbols for sort idioms

Postby michaelk on Wed Jan 04, 2023 10:20 pm

Interesting. But (perhaps also) monadic ∧ and ∨ seem simpler ways to do simple sorts.
michaelk
 
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

Re: Symbols for sort idioms

Postby Veli-Matti on Thu Jan 05, 2023 8:32 am

Hmm..
Behind (and other Adám's proposals) looked pretty interesting and I cannot wait getting my hands on them. But I have to admit that the proposal for monadic ∨ and ∧ sounds easier to grasp.

What is more, you can make the example with current tools:

sort←(⊂⍤⍋⍤⊣⌷⊢)
sort'world'
dlorw
20 10 40 30 40 sort'world'
owlrd


-Veli-Matti
Veli-Matti
 
Posts: 94
Joined: Sat Nov 28, 2009 3:12 pm

PreviousNext

Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest