aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2022-05-27 17:39:06 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2022-05-27 17:39:12 -0400
commit3fd568e004693e447208e1842ab3b1d298eeb293 (patch)
tree81d97e58878f641905280da1e970c267025af786
parent16ad28260975d42a0ad5cb790bd3884c5d293b81 (diff)
Cells modifier diagram
-rw-r--r--doc/rank.md57
-rw-r--r--docs/doc/rank.html81
2 files changed, 138 insertions, 0 deletions
diff --git a/doc/rank.md b/doc/rank.md
index fdf46637..83a0972b 100644
--- a/doc/rank.md
+++ b/doc/rank.md
@@ -2,6 +2,63 @@
# Cells and Rank
+<!--GEN
+xn ← 1‿2‿5⌾(⟨1‿1,2‿1,1‿3⟩⊸⊑) 3‿4⥊0
+d ← 46‿40
+
+rc ← "class=code|stroke-width=1.5|rx=12"
+Ge ← "g"⊸At⊸Enc
+g ← "font-size=18px|fill=currentColor|font-family=BQN,monospace|text-anchor=middle"
+fg ← "font-size=24px"
+dg ← fg∾"|fill=currentColor|opacity=0.9|text-anchor=start"
+lg ← fg∾"|text-anchor=start"
+bg ← "class=bluegreen|stroke-width=2|stroke-linecap=round|style=fill:none|opacity=0.7"
+ag ← "class=green|stroke-width=3|stroke-linecap=round|opacity=0.2"
+cg ← "stroke-width=0.3|fill=none|stroke=currentColor"
+
+Line ← "line" Elt ("xy"≍⌜"12")≍˘○⥊ ·FmtNum d×⊢
+Path ← "path"⊸At ⊸ Elt ⟜ ("d"⊸⋈)
+Rect ← "rect" Elt {(At𝕨)⊢⊘∾"x"‿"y"‿"width"‿"height"≍˘FmtNum𝕩}
+Text ← ("text" Attr "dy"‿"0.33em"∾·Pos d⊸×)⊸Enc
+TTab ← (⍉⋈⌜´)⊸(Text⟜Highlight¨)
+
+off ← 1.2‿2.4
+fo‿co ← ¯1.1‿¯1
+tb ← >0‿¯1⊸⊏¨tx‿ty ← ↕¨sh←⌽≢xn
+dim ← 2‿1×off+⌽≢xn
+Pd ← ∾∾¨⟜FmtNum
+
+Arr ← "M l m l l " Pd ((⊢∾-∾1‿¯1⊸×) 15‿8)∾˜(-˜∾⊣)
+bigarr ← (0.2‿¯0.7+2‿1÷˜sh)∾⌽⊸(¯1‿1‿1‿¯1⊸×⊸∾○∾)(¯1.2‿1.4)‿0.5‿1.9
+
+Tr ← {"transform=translate("∾")"∾˜∾⟜","⊸∾´FmtNum d×off+𝕩‿0}⊸Ge
+CR ← { 𝕨 Rect ⥊-˜` 11 -⊸≍⊸+ d⊸ע𝕩 }
+share ← ⟨
+ cg Ge (CR (⊏tb)≍˘⊢)¨ ty
+ tx‿ty TTab FmtNum xn
+ bg Path "M hv" ∾˜⊸Pd ⥊⌽(15×1.5‿¯1) (+⌾⊑ ≍ -⊸≍∘⊣)˘ 19-⊸≍⊸+d⊸ע⍉tb
+⟩
+
+((∾˜d)×((-∾+˜)0.3‿0.3)+0‿0∾dim) SVG g Ge ⟨
+ rc Rect 0‿0∾d×dim
+ dg Ge 0.2‿0 Text "Cells"
+ 0 Tr share∾⟨
+ cg CR (⊏tb)≍˘¯1.1
+ ag Path "z"∾˜"M vhl l hv" (⊣Pd(∊⟜" v"⊏d˙)⊸×) bigarr
+ lg Ge ¯1‿fo Text Highlight "+˝"
+ tx‿fo TTab FmtNum +˝xn
+ fg Ge ((+˝÷≠)⎉1¨tx⋈2↕ty) TTab <"+"
+ ⟩
+ (1.5+≠tx) Tr share∾⟨
+ cg Ge (CR ·≍˜co≍⊢)¨ ty
+ (ag∾"|style=fill:none") Ge ("" Path (-≠tx)‿0 Arr○(d⊸×) (co+0.2)⋈⊢)¨ ty
+ lg Ge (co-0.2)‿fo Text Highlight "+˝˘"
+ co‿ty TTab FmtNum +˝˘xn
+ ((+˝÷≠)˘ 2↕tx)‿ty TTab <"+"
+ ⟩
+⟩
+-->
+
The Cells modifier `˘` applies a function to major cells of its argument, much like [Each](map.md) applies to elements. Each result from `𝔽` becomes a major cell of the result, which means they must all have the same shape.
The Rank modifier `⎉` generalizes this concept by allowing numbers provided by `𝔾` to specify a rank for each argument: non-negative to indicate the rank of each array passed to `𝔽`, or negative for the number of axes that are mapped over. Cells, which maps over one axis of each argument, is identical to `⎉¯1`. Rank is analogous to the [Depth modifier](depth.md#the-depth-modifier), but the homogeneous structure of an array eliminates some tricky edge cases found in Depth.
diff --git a/docs/doc/rank.html b/docs/doc/rank.html
index aef2edcd..a6752ea1 100644
--- a/docs/doc/rank.html
+++ b/docs/doc/rank.html
@@ -5,6 +5,87 @@
</head>
<div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">doc</a></div>
<h1 id="cells-and-rank"><a class="header" href="#cells-and-rank">Cells and Rank</a></h1>
+<svg viewBox='-13.8 -12 506 240'>
+ <g font-size='18px' fill='currentColor' font-family='BQN,monospace' text-anchor='middle'>
+ <rect class='code' stroke-width='1.5' rx='12' x='0' y='0' width='478.4' height='216'/>
+ <g font-size='24px' fill='currentColor' opacity='0.9' text-anchor='start'><text dy='0.33em' x='9.2' y='0'>Cells</text></g>
+ <g transform='translate(55.2,96)'>
+ <g stroke-width='0.3' fill='none' stroke='currentColor'>
+ <rect x='-11' y='-11' width='160' height='22'/>
+ <rect x='-11' y='29' width='160' height='22'/>
+ <rect x='-11' y='69' width='160' height='22'/>
+ </g>
+ <text dy='0.33em' x='0' y='0'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='46' y='0'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='92' y='0'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='138' y='0'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='0' y='40'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='46' y='40'><tspan class='Number'>1</tspan></text>
+ <text dy='0.33em' x='92' y='40'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='138' y='40'><tspan class='Number'>5</tspan></text>
+ <text dy='0.33em' x='0' y='80'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='46' y='80'><tspan class='Number'>2</tspan></text>
+ <text dy='0.33em' x='92' y='80'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='138' y='80'><tspan class='Number'>0</tspan></text>
+ <path class='bluegreen' stroke-width='2' stroke-linecap='round' style='fill:none' opacity='0.7' d='M142 99h15v-15M3.5 -19h-22.5v22.5'/>
+ <rect stroke-width='0.3' fill='none' stroke='currentColor' x='-11' y='-55' width='160' height='22'/>
+ <path class='green' stroke-width='3' stroke-linecap='round' opacity='0.2' d='M101.2 92v-76h23l-55.2 -56l-55.2 56h23v76z'/>
+ <g font-size='24px' text-anchor='start'><text dy='0.33em' x='-46' y='-44'><tspan class='Function'>+</tspan><tspan class='Modifier'>˝</tspan></text></g>
+ <text dy='0.33em' x='0' y='-44'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='46' y='-44'><tspan class='Number'>3</tspan></text>
+ <text dy='0.33em' x='92' y='-44'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='138' y='-44'><tspan class='Number'>5</tspan></text>
+ <g font-size='24px'>
+ <text dy='0.33em' x='69' y='20'><tspan class='Function'>+</tspan></text>
+ <text dy='0.33em' x='69' y='60'><tspan class='Function'>+</tspan></text>
+ </g>
+ </g>
+ <g transform='translate(308.2,96)'>
+ <g stroke-width='0.3' fill='none' stroke='currentColor'>
+ <rect x='-11' y='-11' width='160' height='22'/>
+ <rect x='-11' y='29' width='160' height='22'/>
+ <rect x='-11' y='69' width='160' height='22'/>
+ </g>
+ <text dy='0.33em' x='0' y='0'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='46' y='0'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='92' y='0'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='138' y='0'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='0' y='40'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='46' y='40'><tspan class='Number'>1</tspan></text>
+ <text dy='0.33em' x='92' y='40'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='138' y='40'><tspan class='Number'>5</tspan></text>
+ <text dy='0.33em' x='0' y='80'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='46' y='80'><tspan class='Number'>2</tspan></text>
+ <text dy='0.33em' x='92' y='80'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='138' y='80'><tspan class='Number'>0</tspan></text>
+ <path class='bluegreen' stroke-width='2' stroke-linecap='round' style='fill:none' opacity='0.7' d='M142 99h15v-15M3.5 -19h-22.5v22.5'/>
+ <g stroke-width='0.3' fill='none' stroke='currentColor'>
+ <rect x='-57' y='-11' width='22' height='22'/>
+ <rect x='-57' y='29' width='22' height='22'/>
+ <rect x='-57' y='69' width='22' height='22'/>
+ </g>
+ <g class='green' stroke-width='3' stroke-linecap='round' opacity='0.2' style='fill:none'>
+ <path d='M147.2 0l-184 0m15 8l-15 -8l15 -8'/>
+ <path d='M147.2 40l-184 0m15 8l-15 -8l15 -8'/>
+ <path d='M147.2 80l-184 0m15 8l-15 -8l15 -8'/>
+ </g>
+ <g font-size='24px' text-anchor='start'><text dy='0.33em' x='-55.2' y='-44'><tspan class='Function'>+</tspan><tspan class='Modifier'>˝˘</tspan></text></g>
+ <text dy='0.33em' x='-46' y='0'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='-46' y='40'><tspan class='Number'>6</tspan></text>
+ <text dy='0.33em' x='-46' y='80'><tspan class='Number'>2</tspan></text>
+ <text dy='0.33em' x='23' y='0'><tspan class='Function'>+</tspan></text>
+ <text dy='0.33em' x='69' y='0'><tspan class='Function'>+</tspan></text>
+ <text dy='0.33em' x='115' y='0'><tspan class='Function'>+</tspan></text>
+ <text dy='0.33em' x='23' y='40'><tspan class='Function'>+</tspan></text>
+ <text dy='0.33em' x='69' y='40'><tspan class='Function'>+</tspan></text>
+ <text dy='0.33em' x='115' y='40'><tspan class='Function'>+</tspan></text>
+ <text dy='0.33em' x='23' y='80'><tspan class='Function'>+</tspan></text>
+ <text dy='0.33em' x='69' y='80'><tspan class='Function'>+</tspan></text>
+ <text dy='0.33em' x='115' y='80'><tspan class='Function'>+</tspan></text>
+ </g>
+ </g>
+</svg>
+
<p>The Cells modifier <code><span class='Modifier'>˘</span></code> applies a function to major cells of its argument, much like <a href="map.html">Each</a> applies to elements. Each result from <code><span class='Function'>𝔽</span></code> becomes a major cell of the result, which means they must all have the same shape.</p>
<p>The Rank modifier <code><span class='Modifier2'>⎉</span></code> generalizes this concept by allowing numbers provided by <code><span class='Function'>𝔾</span></code> to specify a rank for each argument: non-negative to indicate the rank of each array passed to <code><span class='Function'>𝔽</span></code>, or negative for the number of axes that are mapped over. Cells, which maps over one axis of each argument, is identical to <code><span class='Modifier2'>⎉</span><span class='Number'>¯1</span></code>. Rank is analogous to the <a href="depth.html#the-depth-modifier">Depth modifier</a>, but the homogeneous structure of an array eliminates some tricky edge cases found in Depth.</p>
<h2 id="cells"><a class="header" href="#cells">Cells</a></h2>