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 !
26 posts
• Page 2 of 3 • 1, 2, 3
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: 27
- 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: 34
- 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: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
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: 27
- Joined: Wed Dec 23, 2009 8:41 pm
- Location: 39.038681° -105.079070° 2500m
Re: Symbols for sort idioms
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
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.
-
Adam|Dyalog - Posts: 143
- Joined: Thu Jun 25, 2015 1:13 pm
Re: Symbols for sort idioms
Can you tell us what is proposed?
- michaelk
- Posts: 34
- Joined: Wed Feb 10, 2010 8:38 am
Re: Symbols for sort idioms
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
-
Adam|Dyalog - Posts: 143
- Joined: Thu Jun 25, 2015 1:13 pm
Re: Symbols for sort idioms
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
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:
-Veli-Matti
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
26 posts
• Page 2 of 3 • 1, 2, 3
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group