Mix: Difference between revisions

Jump to navigation Jump to search
No change in size ,  02:16, 5 September 2021
Put examples section first
(→‎Examples: Use proper glyph when possible)
(Put examples section first)
Line 3: Line 3:
|}
|}
'''Mix''' (<code>↑</code> or <code>⊃</code> in [[Nested array model|nested]] APLs; '''Disclose''' or '''Open''' <code>></code> in [[Flat array model|flat]] array languages) is a [[primitive function|primitive]] [[monadic function]] which reduces the [[depth]] of its [[argument]] by combining all its [[element]] arrays into a single array. The [[shape]] of its result is then the shape of the argument followed by the common shape of the argument elements. Depending on the definition of Mix, the elements may be required to share the same shape, or they may be extended in shape (with [[fill element]]s) or rank to fit a common shape. In all APLs Mix allows a [[simple array]] argument, and returns it unchanged. Mix is a left inverse to both [[Enclose]] and [[Split]], while the function [[First]], which is identical to Mix on [[scalar]]s, is a left inverse to [[Enclose]] only.
'''Mix''' (<code>↑</code> or <code>⊃</code> in [[Nested array model|nested]] APLs; '''Disclose''' or '''Open''' <code>></code> in [[Flat array model|flat]] array languages) is a [[primitive function|primitive]] [[monadic function]] which reduces the [[depth]] of its [[argument]] by combining all its [[element]] arrays into a single array. The [[shape]] of its result is then the shape of the argument followed by the common shape of the argument elements. Depending on the definition of Mix, the elements may be required to share the same shape, or they may be extended in shape (with [[fill element]]s) or rank to fit a common shape. In all APLs Mix allows a [[simple array]] argument, and returns it unchanged. Mix is a left inverse to both [[Enclose]] and [[Split]], while the function [[First]], which is identical to Mix on [[scalar]]s, is a left inverse to [[Enclose]] only.
== Examples ==
<source lang="apl">
      x ← (0 1 2) (3 4 5) (9 9)
      ⍴x ⍝ x is a nested array, i.e. array of array
3
      ↑x ⍝ note that on the third row, 0 is padded to the end so the matrix can be orthogonal (non-ragged)
0 1 2
3 4 5
9 9 0
      ⍴↑x ⍝ ↑x is a non-nested 2-d array
3 3
</source>
Example application, to find the longest common prefix:
<source lang="apl">
      lcp←{(+/∧\(∧/⊃=⊢)¨↓⍉↑⍵)↑⊃⍵}
      lcp 'flowers' 'flow' 'flip'
fl
      lcp 'choco' 'choky' 'chom'
cho   
</source>


== History ==
== History ==
Line 39: Line 62:
| [[BQN]]                          || Merge    || <code>></code> || [[Shape]]          || {{No}}  || {{No}}
| [[BQN]]                          || Merge    || <code>></code> || [[Shape]]          || {{No}}  || {{No}}
|}
|}
== Examples ==
<source lang="apl">
      x ← (0 1 2) (3 4 5) (9 9)
      ⍴x ⍝ x is a nested array, i.e. array of array
3
      ↑x ⍝ note that on the third row, 0 is padded to the end so the matrix can be orthogonal (non-ragged)
0 1 2
3 4 5
9 9 0
      ⍴↑x ⍝ ↑x is a non-nested 2-d array
3 3
</source>
Example application, to find the longest common prefix:
<source lang="apl">
      lcp←{(+/∧\(∧/⊃=⊢)¨↓⍉↑⍵)↑⊃⍵}
      lcp 'flowers' 'flow' 'flip'
fl
      lcp 'choco' 'choky' 'chom'
cho   
</source>


== External links ==
== External links ==

Navigation menu