Unique: Difference between revisions

Jump to navigation Jump to search
48 bytes added ,  07:19, 23 November 2023
update model for unique to work with all cases of inputs
m (→‎APL model: Explicit version of the Union replacement)
(update model for unique to work with all cases of inputs)
Line 87: Line 87:
It is extended to empty, nested, and arbitrary rank inputs as follows:
It is extended to empty, nested, and arbitrary rank inputs as follows:
<syntaxhighlight lang=apl>
<syntaxhighlight lang=apl>
m ← {0=≢⍵:⍵ ⋄ ↑⊃∪⍨/⌽⊂¨⊂⍤¯1⊢1/⍵}
m ← {⍬≡⍴⍵:,⍵ ⋄ 1≥≢⍵:⍵ ⋄ ↑⊃∪⍨/⌽⊂¨⊂⍤¯1⊢1/⍵}
</syntaxhighlight>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}
Line 94: Line 94:
If modelling the primitive via Union is not desirable due to how similar these two primitives are, it is possible to replace this particular usage of union (not generally, as it relies on the right argument being scalar) as follows:
If modelling the primitive via Union is not desirable due to how similar these two primitives are, it is possible to replace this particular usage of union (not generally, as it relies on the right argument being scalar) as follows:
<syntaxhighlight lang=apl>
<syntaxhighlight lang=apl>
m ← {0=≢⍵:⍵ ⋄ ↑⊃{⍺,(∧/⍺≢¨⍵)/⍵}⍨/⌽⊂¨⊂⍤¯1⊢1/⍵}
m ← {⍬≡⍴⍵:,⍵ ⋄ 1≥≢⍵:⍵ ⋄ ↑⊃{⍺,(∧/⍺≢¨⍵)/⍵}⍨/⌽⊂¨⊂⍤¯1⊢1/⍵}
</syntaxhighlight>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}
2

edits

Navigation menu