{"id":9309,"date":"2026-04-15T10:51:13","date_gmt":"2026-04-15T10:51:13","guid":{"rendered":"https:\/\/www.dyalog.com\/blog\/?p=9309"},"modified":"2026-04-08T08:17:53","modified_gmt":"2026-04-08T08:17:53","slug":"outperforming-nested-arrays-with-classic-apl-techniques-part-2","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2026\/04\/outperforming-nested-arrays-with-classic-apl-techniques-part-2\/","title":{"rendered":"Outperforming Nested Arrays with Classic APL Techniques \u2013 Part 2"},"content":{"rendered":"<p>In my <a href=\"www.dyalog.com\/blog\/2026\/01\/outperforming-nested-arrays-with-classic-apl-techniques-part-1\">previous blog post<\/a> on flat techniques, I demonstrated how you can use a flat representation for nested data, explored searching and structural manipulation of this kind of format, but did not perform any numerical calculations \u2013 that\u2019s what I&#8217;m going to look at now. This is also the topic of a <a href=\"https:\/\/dl.acm.org\/doi\/10.1145\/390009.804488\">classic Quote Quad paper<\/a> by <a href=\"https:\/\/aplwiki.com\/wiki\/Bob_Smith\">\u2018Boolean\u2019 Bob Smith<\/a>. If you\u2019re interested in discovering more once you\u2019ve finished reading this blog post, I urge you to read that paper.<\/p>\n<p>With numeric data, it\u2019s much harder to use an embedded delimiter for partitioning, as there\u2019s unlikely to be a choice of delimiter that will never be part of our data. Therefore, I\u2019ll use a separate Boolean vector indicating the start of each partition (I showed a format like this in the last post, but didn\u2019t put it into practice). Here\u2019s an example:<\/p>\n<pre><code class=\"language-apl\">      test  \u21903 1 4 1 5 9 2 7\r\n      starts\u21901 0 0 1 0 1 0 1\r\n      starts\u2282test  \u235d the nested vector this represents\r\n\u250c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u252c\u2500\u2510\r\n\u25023 1 4\u25021 5\u25029 2\u25027\u2502\r\n\u2514\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2534\u2500\u2518\r\n<\/code><\/pre>\n<h2>Partitioned Sum<\/h2>\n<p>Let\u2019s look at the basic plus reduction, <code class=\"language-apl\">+\/<\/code>. I want to use our partition vector to do the equivalent of <code class=\"language-apl\">+\/\u00a8<\/code> on the partitions.<\/p>\n<pre><code class=\"language-apl\">      +\/\u00a8starts\u2282test  \u235d the goal\r\n8 6 11 7\r\n<\/code><\/pre>\n<p>The trick do this with the partition vector is to use a <code class=\"language-apl\">+\\<\/code> and sample the results at the ends of sub-vectors:<\/p>\n<pre><code class=\"language-apl\">      [\r\n          test\r\n          +\\test\r\n          starts    \u235d start of each sub-vector\r\n          1\u233dstarts  \u235d end of each sub-vector\r\n      ]\r\n3 1 4 1  5  9  2  7\r\n3 4 8 9 14 23 25 32\r\n1 0 0 1  0  1  0  1\r\n0 0 1 0  1  0  1  1\r\n      (1\u233dstarts)\/+\\test  \u235d sample +\\test at the end of each sub-vector\r\n8 14 25 32\r\n<\/code><\/pre>\n<p>The important thing to notice here is that <code class=\"language-apl\">8<\/code> is the sum of the first sub-vector, <code class=\"language-apl\">14<\/code> is the sum of the first and second sub-vectors, <code class=\"language-apl\">25<\/code> is the sum of the first, second, and third sub-vectors, and so on. This is the same as <code class=\"language-apl\">+\\+\/\u00a8starts\u2282test<\/code>:<\/p>\n<pre><code class=\"language-apl\">      +\\+\/\u00a8starts\u2282test\r\n8 14 25 32\r\n<\/code><\/pre>\n<p>To recover the sum of each sub-vector, I can undo the <code class=\"language-apl\">+\\<\/code> by finding the pairwise differences between the results:<\/p>\n<pre><code class=\"language-apl\">      \u00af2-\/0,(1\u233dstarts)\/+\\test\r\n8 6 11 7\r\n<\/code><\/pre>\n<p>It&#8217;s time to try it on some larger data! I\u2019ll need some random numbers, and some random partition points.<\/p>\n<pre><code class=\"language-apl\">      numbers\u2190?1E6\u23741000         \u235d random (whole) numbers\r\n      starts\u21900.8&lt;?1E6\u23740         \u235d random partition points\r\n      (\u2283starts)\u21901               \u235d must start with a 1\r\n      nested\u2190starts\u2282numbers     \u235d to compare against\r\n      [10\u2191numbers \u22c4 10\u2191starts]  \u235d let's look at it\r\n123 898 773 377 564 395 306 673 84 62\r\n  1   0   0   1   0   0   0   0  0  0\r\n<\/code><\/pre>\n<p>Now, do I see a speed improvement by using the flat version of <code class=\"language-apl\">+\/\u00a8<\/code>?<\/p>\n<pre><code class=\"language-apl\">      ]RunTime -c \"+\/\u00a8nested\" \"\u00af2-\/0,(1\u233dstarts)\/+\\numbers\" \r\n                                                                                     \r\n  +\/\u00a8nested                  \u2192 2.7E\u00af3 |   0% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n  \u00af2-\/0,(1\u233dstarts)\/+\\numbers \u2192 1.3E\u00af3 | -53% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n<\/code><\/pre>\n<p>Great, it\u2019s around twice as fast. I didn&#8217;t include the cost of converting between formats here &#8211; including the <code class=\"language-apl\">starts\u2282numbers<\/code> in this comparison would tip the scales even further.<\/p>\n<p>It doesn\u2019t end here, though. I generated partitions with the expression <code class=\"language-apl\">0.8&lt;1E6\u23740<\/code>, which includes a <code class=\"language-apl\">1<\/code>\u00a0approximately every 5 places. By changing that <code class=\"language-apl\">0.8<\/code> constant, I can change the density of <code class=\"language-apl\">1<\/code>s in our partition vector, thereby controlling the size and count of sub-vectors that the data is chopped up into. When I increase it, there will be fewer, larger, sub-vectors; when I decrease it, there will be more, smaller, ones. Changing this constant has an effect on the relative performance of the flat method.<\/p>\n<p>Using <code class=\"language-apl\">0.5<\/code>:<\/p>\n<pre><code class=\"language-apl\">      \u235d .. remake data ..                                   \r\n      ]RunTime -c \"+\/\u00a8nested\" \"\u00af2-\/0,(1\u233dstarts)\/+\\numbers\"            \r\n                                                                                     \r\n  +\/\u00a8nested                  \u2192 6.3E\u00af3 |   0% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395 \r\n  \u00af2-\/0,(1\u233dstarts)\/+\\numbers \u2192 1.8E\u00af3 | -72% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n<\/code><\/pre>\n<p>Using <code class=\"language-apl\">0.9<\/code>:<\/p>\n<pre><code class=\"language-apl\">      \u235d .. remake data ..                                     \r\n      ]RunTime -c \"+\/\u00a8nested\" \"\u00af2-\/0,(1\u233dstarts)\/+\\numbers\"             \r\n                                                                                     \r\n  +\/\u00a8nested                  \u2192 1.7E\u00af3 |   0% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395 \r\n  \u00af2-\/0,(1\u233dstarts)\/+\\numbers \u2192 1.1E\u00af3 | -32% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n<\/code><\/pre>\n<p>Using <code class=\"language-apl\">0.99<\/code>:<\/p>\n<pre><code class=\"language-apl\">      \u235d .. remake data ..                                      \r\n      ]RunTime -c \"+\/\u00a8nested\" \"\u00af2-\/0,(1\u233dstarts)\/+\\numbers\"              \r\n                                                                                      \r\n  +\/\u00a8nested                  \u2192 2.1E\u00af4 |    0% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395                           \r\n  \u00af2-\/0,(1\u233dstarts)\/+\\numbers \u2192 5.8E\u00af4 | +184% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n<\/code><\/pre>\n<p>This reveals a lot. The greater the constant, the worse our flat version becomes in terms of performance. This makes sense \u2013 nested arrays bring with them some overheads (as discussed in my previous blog post on this topic), and the number and size of nested arrays will have an effect on these overheads. There\u2019s clearly a turning point at which the extra effort we\u2019re putting in for our flat version outweighs the benefits we get by avoiding nesting. Ultimately, it depends on the size of the partitions that you\u2019re working with.<\/p>\n<p>It should be emphasised that the best benchmark is your own application running on real data. You might want to use a flat partitioned <code class=\"language-apl\">+\/\u00a8<\/code>, but you might find that your partitions are too large to give you any benefit. You should check that it gives <em>you<\/em> an improvement!<\/p>\n<p>There\u2019s another caveat to be aware of when using these flat techniques for numeric calculations: non-whole numbers can cause problems. For example, here&#8217;s the partitioned <code class=\"language-apl\">+\/<\/code> on some non-integer data:<\/p>\n<pre><code class=\"language-apl\">      numbers+\u2190?1E6\u23740  \u235d add a fraction to each\r\n      nested\u2190starts\u2282numbers\r\n      (+\/\u00a8nested)\u2261(\u00af2-\/0,(1\u233dstarts)\/+\\numbers)\r\n0\r\n<\/code><\/pre>\n<p>What\u2019s happening here? Is the method wrong? Well, no, but the result <em>is<\/em> different. The reason is that non-whole numbers are stored with a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Floating-point_arithmetic\">floating-point<\/a> representation in the interpreter (64-bit binary floating-point, under the default <a href=\"https:\/\/docs.dyalog.com\/20.0\/language-reference-guide\/system-functions\/fr\/\"><code>\u2395FR\u2190645<\/code><\/a>). The issue with this is that addition on floating-point numbers is not associative, that is,\u00a0<code class=\"language-apl\">(a+b)+c<\/code> might be a tiny bit different from <code class=\"language-apl\">a+(b+c)<\/code>. We are relying on the associativity of addition to \u2018undo the <code class=\"language-apl\">+\\<\/code>\u2019, so some small differences are going to build up.<\/p>\n<p><a href=\"https:\/\/docs.dyalog.com\/20.0\/language-reference-guide\/system-functions\/ct\/\"><code>\u2395CT<\/code><\/a> allows a level of \u2018fuzziness\u2019 in equality comparisons, but not enough to cover all the differences in the example. It is important to be aware that, when you have non-whole numbers, the partitioned versions of numeric operations can accumulate some errors due to the behaviour of floating-point arithmetic. If you\u2019re working in a context where you need <em>exactly<\/em> the same results as a regular <code>+\/\u00a8<\/code>, you might need to stick to the nested format.<\/p>\n<h2>Partitioned Any (Or-Reduction)<\/h2>\n<p>When I looked at counting words containing an <code class=\"language-apl\">'a'<\/code> in the last post, I teased you by mentioning some expressions that I would return to. Here are the two expressions that I promised to investigate further:<\/p>\n<pre><code class=\"language-apl\">      +\/2&lt;\/0,(1\u233dV=';')\/+\\V='a'\r\n281193\r\n      (V=';'){+\/(\u237a\/\u2375)\u2265a\/1\u233da\u2190\u237a\/\u2368\u2375\u2228\u237a}V='a'\r\n281193\r\n<\/code><\/pre>\n<p>You might have noticed that the first of these expressions is very similar to the partitioned sum from the previous section but with <code class=\"language-apl\">\u00af2-\/<\/code> replaced by <code class=\"language-apl\">2&lt;\/<\/code>. This is essentially performing a <code class=\"language-apl\">\u2228\/<\/code> on each word, after comparing with <code class=\"language-apl\">'a'<\/code>. But how does this compare to the partitioned <code class=\"language-apl\">+\/<\/code>?<\/p>\n<p>Some test data:<\/p>\n<pre><code class=\"language-apl\">      bools \u21900 1 0 1 1 1 0 0 0 1 0 0 0\r\n      starts\u21901 0 1 0 0 1 0 0 1 1 1 0 0\r\n<\/code><\/pre>\n<p>I&#8217;m focusing on a <em>Boolean<\/em> <code class=\"language-apl\">\u2228\/<\/code> here, so just <code class=\"language-apl\">1<\/code>s and <code class=\"language-apl\">0<\/code>s. The <code class=\"language-apl\">starts<\/code> vector chops up <code class=\"language-apl\">bools<\/code>\u00a0as follows:<\/p>\n<pre><code class=\"language-apl\">      starts\u2282bools\r\n\u250c\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u252c\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2510\r\n\u25020 1\u25020 1 1\u25021 0 0\u25020\u25021\u25020 0 0\u2502\r\n\u2514\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2534\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2518\r\n<\/code><\/pre>\n<p>In this context, I can interpret <code class=\"language-apl\">+\\bools<\/code> as the number of <code class=\"language-apl\">1<\/code>s that have appeared in <code class=\"language-apl\">bools<\/code>, up to and including each element:<\/p>\n<pre><code class=\"language-apl\">      [\r\n          bools\r\n          +\\bools   \u235d number of 1s seen so far\r\n          1\u233dstarts  \u235d ends of each sub-vector\r\n      ]\r\n0 1 0 1 1 1 0 0 0 1 0 0 0\r\n0 1 1 2 3 4 4 4 4 5 5 5 5\r\n0 1 0 0 1 0 0 1 1 1 0 0 1\r\n<\/code><\/pre>\n<p>By sampling from the end of each sub-vector with <code class=\"language-apl\">(1\u233dstarts)\/<\/code>, I can obtain the number of <code class=\"language-apl\">1<\/code>s that appeared in or before each sub-vector:<\/p>\n<pre><code class=\"language-apl\">      (1\u233dstarts)\/+\\bools\r\n1 3 4 4 5 5\r\n<\/code><\/pre>\n<p>This vector shows which sub-vectors included a <code class=\"language-apl\">1<\/code>, as these are the places where the cumulative count of <code class=\"language-apl\">1<\/code>s increases. I can find those places with a pairwise <code class=\"language-apl\">&lt;<\/code>:<\/p>\n<pre><code class=\"language-apl\">      2&lt;\/0,(1\u233dstarts)\/+\\bools\r\n1 1 1 0 1 0\r\n      \u2228\/\u00a8starts\u2282bools  \u235d check against the nested version\r\n1 1 1 0 1 0\r\n<\/code><\/pre>\n<p>The difference from the flat <code class=\"language-apl\">+\/<\/code> (which used a pairwise <em>subtraction<\/em>) is due to the fact that there the magnitude of the difference between each sub-vector was important, but here it is only relevant that there is a difference at all.<\/p>\n<p>If this works so well, why did I show you two different expressions for a partitioned <code class=\"language-apl\">\u2228\/<\/code>? The expression I just worked through uses an integer vector (<code class=\"language-apl\">+\\bools<\/code>) to determine its result. The other expression is trickier to understand, but does everything using just Boolean vectors (I&#8217;ll show the details later on). This means a boost in performance:<\/p>\n<pre><code class=\"language-apl\">      (starts bools)\u21900.9&lt;1E6?\u2364\u2374\u00a80 0\r\n      (\u2283starts)\u21901       \r\n      nested\u2190starts\u2282bools   \r\n      ]RunTime -c \"2&lt;\/0,(1\u233dstarts)\/+\\bools\" \"starts{(\u237a\/\u2375)\u2265a\/1\u233da\u2190\u237a\/\u2368\u2375\u2228\u237a}bools\"   \r\n                                                                                          \r\n  2&lt;\/0,(1\u233dstarts)\/+\\bools         \u2192 7.8E\u00af4 |   0% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395 \r\n  starts{(\u237a\/\u2375)\u2265a\/1\u233da\u2190\u237a\/\u2368\u2375\u2228\u237a}bools \u2192 2.3E\u00af4 | -71% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n<\/code><\/pre>\n<p>This is due to a trick that the Dyalog interpreter does with Boolean arrays. Since the only two values that need to be stored are <code class=\"language-apl\">0<\/code> and <code class=\"language-apl\">1<\/code>, the interpreter only uses a single bit to store each value, compared to between 8 and 64 bits for arbitrary numbers or characters. This saves on space, since 8 or more values can be stored in the same space as a number takes up. It also saves on time in many cases, as your CPU has dedicated instructions for Boolean operations on bits and because less data needs to be moved into and out of the CPU.<\/p>\n<p><code class=\"language-apl\">{(\u237a\/\u2375)\u2265a\/1\u233da\u2190\u237a\/\u2368\u2375\u2228\u237a}<\/code> is not an easy function to understand. It&#8217;s easier to understand by breaking it down and understanding what the intermediate results really <em>mean<\/em> at each step. Some complications come from <code class=\"language-apl\">1<\/code>s in the data occupying the same index as <code class=\"language-apl\">1<\/code>s in the partition vector. So, for now, I&#8217;ll use some sample data that doesn&#8217;t include that case:<\/p>\n<pre><code class=\"language-apl\">      bools \u21900 1 0 0 1 1 0 0 0 0 0 1\r\n      starts\u21901 0 0 1 0 0 1 0 0 1 0 0\r\n      starts\u2282bools  \u235d nested vector represented by this partition vector\r\n\u250c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2510\r\n\u25020 1 0\u25020 1 1\u25020 0 0\u25020 0 1\u2502\r\n\u2514\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2518\r\n<\/code><\/pre>\n<p>Next, <code class=\"language-apl\">bools\u2228starts<\/code> gives us a mask of the places that are either beginnings of a partition or a <code class=\"language-apl\">1<\/code> in the data:<\/p>\n<pre><code class=\"language-apl\">      [bools \u22c4 starts \u22c4 bools\u2228starts]\r\n0 1 0 0 1 1 0 0 0 0 0 1\r\n1 0 0 1 0 0 1 0 0 1 0 0\r\n1 1 0 1 1 1 1 0 0 1 0 1\r\n<\/code><\/pre>\n<p>Using this mask to compress <code class=\"language-apl\">starts<\/code>\u00a0returns something very interesting. In this new vector, a <code class=\"language-apl\">1<\/code> corresponds to the start of a partition, and a <code class=\"language-apl\">0<\/code> corresponds to a <code class=\"language-apl\">1<\/code> inside a partition.<\/p>\n<pre><code class=\"language-apl\">                     \u250c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2510\r\n      starts\u2282bools:  \u25020 1 0\u25020 1 1\u25020 0 0\u25020 0 1\u2502\r\n                     \u2514\u2191\u2500\u2191\u2500\u2500\u2534\u2191\u2500\u2191\u2500\u2191\u2534\u2191\u2500\u2500\u2500\u2500\u2534\u2191\u2500\u2500\u2500\u2191\u2518\r\n                      \u2514\u2510\u2514\u2510 \u250c\u2518\u250c\u2518\u250c\u2518\u250c\u2518\u250c\u2500\u2500\u2500\u2500\u2518   \u2502\r\nstarts\/\u2368bools\u2228starts:  1 0 1 0 0 1 1 0\u2500\u2500\u2500\u2500\u2500\u2500\u2518\r\n<\/code><\/pre>\n<p>With this sample data, where there are no <code class=\"language-apl\">1<\/code>s at the start of partitions, it now becomes fairly straightforward to see whether\u00a0there&#8217;s a <code class=\"language-apl\">1<\/code> in a partition \u2013 if a <code class=\"language-apl\">1<\/code> in the new vector is followed by a <code class=\"language-apl\">0<\/code>, then there&#8217;s an internal <code class=\"language-apl\">1<\/code>, otherwise, if it&#8217;s followed by a <code class=\"language-apl\">1<\/code>, then there isn&#8217;t. I can easily extract the value following each <code class=\"language-apl\">1<\/code> in this vector:<\/p>\n<pre><code class=\"language-apl\">      a\u2190starts\/\u2368bools\u2228starts\r\n      a\/1\u233da\r\n0 0 1 0\r\n<\/code><\/pre>\n<p>A <code class=\"language-apl\">0<\/code> here indicates a <code class=\"language-apl\">1<\/code> after the first place in a partition, while a <code class=\"language-apl\">1<\/code> indicates the absence of that, so I need to flip the bits:<\/p>\n<pre><code class=\"language-apl\">      ~a\/1\u233da\r\n1 1 0 1\r\n      \u2228\/\u00a8starts\u2282bools\r\n1 1 0 1\r\n<\/code><\/pre>\n<p>If I put all this together in a function, I get <code class=\"language-apl\">{~a\/1\u233da\u2190\u237a\/\u2368\u2375\u2228\u237a}<\/code>. But I&#8217;ve not finished yet! This is different from the original function because I&#8217;m still not handling the case where a partition begins with a <code class=\"language-apl\">1<\/code>. I need to use different test data to investigate this case:<\/p>\n<pre><code class=\"language-apl\">      bools \u21900 0 0 1 1 0 1 0 0 0 0 1\r\n      starts\u21901 0 0 1 0 0 1 0 0 1 0 0\r\n      starts\u2282bools\r\n\u250c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2510\r\n\u25020 0 0\u25021 1 0\u25021 0 0\u25020 0 1\u2502\r\n\u2514\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2518\r\n      \u2228\/\u00a8starts\u2282bools              \u235d what I want\r\n0 1 1 1\r\n      ~a\/1\u233da\u2190starts\/\u2368bools\u2228starts  \u235d what I get \u2013 a false negative!\r\n0 1 0 1\r\n<\/code><\/pre>\n<p>In addition to <code class=\"language-apl\">1<\/code>s that are already in the result (which indicate a <code class=\"language-apl\">1<\/code> appearing in a partition excluding the first place), I want to include a <code class=\"language-apl\">1<\/code> when there is a <code class=\"language-apl\">1<\/code> in the first place in a partition. I can see what each partition begins with by compressing the data vector with the partition vector:<\/p>\n<pre><code class=\"language-apl\">      starts\/bools\r\n0 1 1 0\r\n<\/code><\/pre>\n<p>Including these <code class=\"language-apl\">1<\/code>s in the result:<\/p>\n<pre><code class=\"language-apl\">      r\u2190~a\/1\u233da\u2190starts\/\u2368bools\u2228starts\r\n      (starts\/bools)\u2228r\r\n0 1 1 1\r\n<\/code><\/pre>\n<p>Fantastic! Now the method works properly. There&#8217;s one minor tweak I can make, exploiting the fact that <code class=\"language-apl\">\u2228~<\/code> is equivalent to <code class=\"language-apl\">\u2265<\/code> on Boolean data:<\/p>\n<pre><code class=\"language-apl\">      (starts\/bools)\u2228~a\/1\u233da\u2190starts\/\u2368bools\u2228starts\r\n0 1 1 1\r\n      (starts\/bools)\u2265 a\/1\u233da\u2190starts\/\u2368bools\u2228starts\r\n0 1 1 1\r\n<\/code><\/pre>\n<p>And with that, I have all the pieces to construct the original function: <code class=\"language-apl\">{(\u237a\/\u2375)\u2265a\/1\u233da\u2190\u237a\/\u2368\u2375\u2228\u237a}<\/code>.<\/p>\n<h2>Where to go for more<\/h2>\n<p>I&#8217;ve only taken a few small steps into the techniques for working with partitioned arrays. I&#8217;ve explored a few reductions, but what about the rest? What about scans? To learn more, I strongly encourage you to read <a href=\"https:\/\/dl.acm.org\/doi\/10.1145\/390009.804488\">Bob Smith&#8217;s paper<\/a> on the topic, and to go to APLcart for a list of partitioned <a href=\"https:\/\/aplcart.info?q=fast%20reduction\">reductions<\/a> and <a href=\"https:\/\/aplcart.info?q=fast%20scan\">scans<\/a> written with modern APL features.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my previous blog post on flat techniques, I demonstrated how you can use a flat representation for nested data, explored searching and structural manipulation of this kind of format, but did not perform any numerical calculations \u2013 that\u2019s what &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2026\/04\/outperforming-nested-arrays-with-classic-apl-techniques-part-2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":38,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-9309","post","type-post","status-publish","format-standard","hentry","category-tips-tricks"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/9309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/comments?post=9309"}],"version-history":[{"count":15,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/9309\/revisions"}],"predecessor-version":[{"id":9325,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/9309\/revisions\/9325"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=9309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=9309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=9309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}