Symbols for sort idioms
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 !
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 !
14 posts
• Page 2 of 2 • 1, 2
Re: Symbols for sort idioms
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 .
` 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 .
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 .
-
Bob Armstrong - Posts: 21
- Joined: Wed Dec 23, 2009 8:41 pm
- Location: 39.038681° -105.079070° 2500m
Re: Symbols for sort idioms
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: 31
- Joined: Wed Feb 10, 2010 8:38 am
Re: Symbols for sort idioms
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.
-
Phil Last - Posts: 599
- Joined: Thu Jun 18, 2009 6:29 pm
Re: Symbols for sort idioms
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 .
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 .
-
Bob Armstrong - Posts: 21
- Joined: Wed Dec 23, 2009 8:41 pm
- Location: 39.038681° -105.079070° 2500m
14 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group