Mesh: Difference between revisions

Jump to navigation Jump to search
69 bytes removed ,  10:16, 18 March 2020
(→‎APL models: Link to FinnAPL plus minor editing)
Line 46: Line 46:
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.
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>.
<source lang=apl>
<source lang=apl>
t←(~u)\a ⋄ (u/t)←b ⋄ t
t←(~u)\a ⋄ (u/t)←b ⋄ t

Navigation menu