Mesh: Difference between revisions

Jump to navigation Jump to search
78 bytes added ,  10:00, 18 March 2020
→‎APL models: Link to FinnAPL plus minor editing
(Bernecky's paper)
(→‎APL models: Link to FinnAPL plus minor editing)
Line 44: Line 44:
(b,a)[⍋⍒u]  ⍝ Reversed order by sorting u the other way
(b,a)[⍋⍒u]  ⍝ Reversed order by sorting u the other way
</source>
</source>
These solutions were published in 1971 by [[Bob Smith]], who attributes them to Luther Woodrum by way of [[Ken Iverson]].<ref>[[Bob Smith|Smith, Bob]]. "Problem section". [[APL Quote-Quad]] Vol. III No. 2&3, p.61.</ref><ref>[[Hui, Roger|Roger Hui]]. [https://www.jsoftware.com/papers/mesh.htm "An Amuse-Bouche from APL History"].</ref> The idea is that every element of <source lang=apl inline>a</source> and <source lang=apl inline>b</source> should be included in the final result, but they are ordered based on <source lang=apl inline>u</source>, so that elements of <source lang=apl inline>a</source> correspond to 0s and those of <source lang=apl inline>b</source> correspond to 1s. Given such a vector, [[Sort by|sorting]] it according to <source lang=apl inline>u</source>, or equivalently, permuting by the [[Grade]] of <source lang=apl inline>u</source>, would return it to the separated vector <source lang=apl inline>a,b</source>. It follows that applying the inverse [[permutation]] <source lang=apl inline>⍋⍋u</source> of <source lang=apl inline>⍋u</source> transforms <source lang=apl inline>a,b</source> into the meshed vector.
These solutions were published in 1971 by [[Bob Smith]], who attributes them to Luther Woodrum by way of [[Ken Iverson]].<ref>[[Bob Smith|Smith, Bob]]. "Problem section". [[APL Quote-Quad]] Vol. III No. 2&3, p.61.</ref><ref>[[Roger Hui|Hui, Roger]]. [https://www.jsoftware.com/papers/mesh.htm "An Amuse-Bouche from APL History"].</ref> They also appear in the [[FinnAPL idiom library]]. The idea is that every element of <source lang=apl inline>a</source> and <source lang=apl inline>b</source> should be included in the final result, but they are ordered based on <source lang=apl inline>u</source>, so that elements of <source lang=apl inline>a</source> correspond to 0s and those of <source lang=apl inline>b</source> correspond to 1s. Given such a vector, [[Sort by|sorting]] it according to <source lang=apl inline>u</source>, or equivalently, permuting by the [[Grade]] of <source lang=apl inline>u</source>, would return it to the separated vector <source lang=apl inline>a,b</source>. It follows that applying the inverse [[permutation]] <source lang=apl inline>⍋⍋u</source> of <source lang=apl inline>⍋u</source> transforms <source lang=apl inline>a,b</source> into the meshed vector.


Another, more straightforward strategy uses [[selective assignment]] and [[Expand]]. It creates a temporary vector <source lang=apl inline>t</source>, placing elements of <source lang=apl inline>a</source> in the appropriate positions with [[Expand]], and then inserts elements of <source lang=apl inline>b</source> in the appropriate positions by assigning to the [[Compress]] of <source lang=apl inline>t</source>. Of course these steps could also be performed in the opposite order.
Another, more straightforward strategy uses [[selective assignment]] and [[Expand]]. It creates a temporary vector <source lang=apl inline>t</source>, placing elements of <source lang=apl inline>a</source> in the appropriate positions with [[Expand]], and then inserts elements of <source lang=apl inline>b</source> in the appropriate positions by assigning to the [[Compress]] of <source lang=apl inline>t</source>. Of course these steps could also be performed in the opposite order.
Line 53: Line 53:
<source lang=apl>
<source lang=apl>
a⍨⍢((~u)∘⌿) b⍨⍢(u∘⌿) a,b
a⍨⍢((~u)∘⌿) b⍨⍢(u∘⌿) a,b
</source>
</source>{{Works in|[[dzaima/APL]]}}
Here any vector of the same length could be used in place of <source lang=apl inline>a,b</source>.
Here any vector of the same length could be used in place of <source lang=apl inline>a,b</source>.


Navigation menu