aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2022-07-12 21:43:15 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2022-07-12 21:43:15 -0400
commitd4cbba4377779d7ce5af0035525883310afa7cc4 (patch)
tree9041bc589980ba65fdc5dab21e6c658604f7226b
parentde0b28520bc7bb65459db17c7451f808f6ef4e3e (diff)
Windows diagram
-rw-r--r--doc/reshape.md1
-rw-r--r--doc/windows.md36
-rw-r--r--docs/doc/windows.html49
3 files changed, 85 insertions, 1 deletions
diff --git a/doc/reshape.md b/doc/reshape.md
index b4081a53..21d979ee 100644
--- a/doc/reshape.md
+++ b/doc/reshape.md
@@ -21,7 +21,6 @@ Path ← ("path"At⊣) Elt "d"⋈⊢
pad ← 48‿51 ⋄ sh ← 0‿0
dim ← (pad-0‿7) + ¯1⊑¨ tx‿ty ← pad+d× ¯1(⊑{⟨↕𝕨,⥊+⌜´(↕¨×·×`⌾⌽1+«)𝕩⟩}↓)≢xt
tb ← >0‿¯1⊸⊏¨tx‿ty
-cg ← "font-size=19px|text-anchor=middle"
bp ← ⥊⌽(20×1.5‿¯1) (+⌾⊑ ≍ -⊸≍∘⊣)˘ 29‿21-⊸≍⊸+⍉tb
(((-∾+˜)64‿15)+sh∾dim) SVG g Ge ⟨
diff --git a/doc/windows.md b/doc/windows.md
index 6c009143..baae3efc 100644
--- a/doc/windows.md
+++ b/doc/windows.md
@@ -2,6 +2,42 @@
# Windows
+<!--GEN
+zt ← (w←5) ↕ xt ← Highlight∘•Repr¨ ↕8
+d ← 40‿40
+
+Ge ← "g"⊸At⊸Enc
+rc ← At "class=code|stroke-width=1.5|rx=12"
+g ← "fill=currentColor|font-family=BQN,monospace|text-anchor=middle|font-size=18px"
+bg ← "class=bluegreen|stroke-width=3|stroke-linecap=round|style=fill:none|opacity=0.7"
+sg ← "fill=none|stroke-width=1|stroke=currentColor"
+col ← {"class"‿𝕩≍"style"‿"fill:none"}¨"purple"‿"red"‿"yellow"‿"green"
+
+Text ← ("text" Attr "dy"‿"0.33em"∾·Pos d⊸×)⊸Enc
+Rect ← "rect" Elt Pos⊸∾⟜("width"‿"height"≍˘FmtNum)˝{𝕨⊢⊘∾𝔽𝕩}
+Path ← ("path"At⊣) Elt "d"⋈⊢
+
+ay ← ¯2 ⋄ lx ← ¯1.2
+Exp ← (-≍+˜)⊸+
+dim ← 48‿36 Exp d⊸ע lx‿ay ≍ ⟨lx-˜zt-○≠⊏xt,-ay⟩ + ¯1⊑¨ tx‿ty ← ⌽↕¨≢zt
+my ← 2÷˜¯1⊑ty
+
+Pd ← ∾∾¨⟜FmtNum
+l ← 6‿15
+br ← ∾ ((0.6-⊸⋈⊸+0⋈1-˜≠xt)((0‿¯1×l)+d×⋈)¨ay) ("M l l "Pd⥊∘∾)¨ ⋈⟜⌽ -⌾⊑⊸≍l
+bp ← ⥊⌽(20×1.5‿¯1) (+⌾⊑ ≍ -⊸≍∘⊣)˘ 28‿24-⊸≍⊸+ d×⍉>0‿¯1⊸⊏¨tx‿ty
+sl ← (0⋈¨ty)≍ty⋈¨ay+0.05×ty-my
+
+(⥊48‿16 Exp dim) SVG g Ge ⟨
+ rc Rect dim
+ "text-anchor=end" Ge ay‿my lx⊸⋈⊸Text⟜Highlight¨ (⊢⋈(FmtNum w)∾"↕"∾⊢)"𝕩"
+ sg Ge col Rect⟜{d⊸ע¯0.1 Exp (¯0.5+𝕩)≍⟨≠tx,1⟩}¨⎉1 sl
+ bg Path br ∾ "M hv" ∾˜⊸Pd bp
+ ((↕≠xt)⋈⌜ay) Text¨ xt
+ (⍉tx⋈⌜ty) Text¨ zt
+⟩
+-->
+
The Windows function returns all slices, or contiguous subarrays, with shape (well, shape prefix) `𝕨` from `𝕩`. It might also be seen as sliding a moving window along `𝕩`.
This function replaces APL's Windowed Reduction, J's more general Infix operator, and Dyalog APL's Stencil, which is adapted from one case of J's Cut operator. In BQN, it's strongly preferred to use functions, and not modifiers, for array manipulation. Functions are simpler with fewer moving parts, and more concrete, since the array results can always be viewed right away.
diff --git a/docs/doc/windows.html b/docs/doc/windows.html
index 67e6a9f8..d48db69b 100644
--- a/docs/doc/windows.html
+++ b/docs/doc/windows.html
@@ -5,6 +5,55 @@
</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="windows"><a class="header" href="#windows">Windows</a></h1>
+<svg viewBox='-144 -132 520 304'>
+ <g fill='currentColor' font-family='BQN,monospace' text-anchor='middle' font-size='18px'>
+ <rect class='code' stroke-width='1.5' rx='12' x='-96' y='-116' width='424' height='272'/>
+ <g text-anchor='end'>
+ <text dy='0.33em' x='-48' y='-80'><tspan class='Value'>𝕩</tspan></text>
+ <text dy='0.33em' x='-48' y='60'><tspan class='Number'>5</tspan><tspan class='Function'>↕</tspan><tspan class='Value'>𝕩</tspan></text>
+ </g>
+ <g fill='none' stroke-width='1' stroke='currentColor'>
+ <rect class='purple' style='fill:none' x='-16' y='-16' width='192' height='32'/>
+ <rect class='red' style='fill:none' x='-16' y='24' width='192' height='32'/>
+ <rect class='yellow' style='fill:none' x='-16' y='64' width='192' height='32'/>
+ <rect class='green' style='fill:none' x='-16' y='104' width='192' height='32'/>
+ <rect class='purple' style='fill:none' x='-16' y='-99' width='192' height='32'/>
+ <rect class='red' style='fill:none' x='24' y='-97' width='192' height='32'/>
+ <rect class='yellow' style='fill:none' x='64' y='-95' width='192' height='32'/>
+ <rect class='green' style='fill:none' x='104' y='-93' width='192' height='32'/>
+ </g>
+ <path class='bluegreen' stroke-width='3' stroke-linecap='round' style='fill:none' opacity='0.7' d='M-24 -95l-6 15l6 15M304 -95l6 15l-6 15M168 144h20v-20M2 -24h-30v30'/>
+ <text dy='0.33em' x='0' y='-80'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='40' y='-80'><tspan class='Number'>1</tspan></text>
+ <text dy='0.33em' x='80' y='-80'><tspan class='Number'>2</tspan></text>
+ <text dy='0.33em' x='120' y='-80'><tspan class='Number'>3</tspan></text>
+ <text dy='0.33em' x='160' y='-80'><tspan class='Number'>4</tspan></text>
+ <text dy='0.33em' x='200' y='-80'><tspan class='Number'>5</tspan></text>
+ <text dy='0.33em' x='240' y='-80'><tspan class='Number'>6</tspan></text>
+ <text dy='0.33em' x='280' y='-80'><tspan class='Number'>7</tspan></text>
+ <text dy='0.33em' x='0' y='0'><tspan class='Number'>0</tspan></text>
+ <text dy='0.33em' x='40' y='0'><tspan class='Number'>1</tspan></text>
+ <text dy='0.33em' x='80' y='0'><tspan class='Number'>2</tspan></text>
+ <text dy='0.33em' x='120' y='0'><tspan class='Number'>3</tspan></text>
+ <text dy='0.33em' x='160' y='0'><tspan class='Number'>4</tspan></text>
+ <text dy='0.33em' x='0' y='40'><tspan class='Number'>1</tspan></text>
+ <text dy='0.33em' x='40' y='40'><tspan class='Number'>2</tspan></text>
+ <text dy='0.33em' x='80' y='40'><tspan class='Number'>3</tspan></text>
+ <text dy='0.33em' x='120' y='40'><tspan class='Number'>4</tspan></text>
+ <text dy='0.33em' x='160' y='40'><tspan class='Number'>5</tspan></text>
+ <text dy='0.33em' x='0' y='80'><tspan class='Number'>2</tspan></text>
+ <text dy='0.33em' x='40' y='80'><tspan class='Number'>3</tspan></text>
+ <text dy='0.33em' x='80' y='80'><tspan class='Number'>4</tspan></text>
+ <text dy='0.33em' x='120' y='80'><tspan class='Number'>5</tspan></text>
+ <text dy='0.33em' x='160' y='80'><tspan class='Number'>6</tspan></text>
+ <text dy='0.33em' x='0' y='120'><tspan class='Number'>3</tspan></text>
+ <text dy='0.33em' x='40' y='120'><tspan class='Number'>4</tspan></text>
+ <text dy='0.33em' x='80' y='120'><tspan class='Number'>5</tspan></text>
+ <text dy='0.33em' x='120' y='120'><tspan class='Number'>6</tspan></text>
+ <text dy='0.33em' x='160' y='120'><tspan class='Number'>7</tspan></text>
+ </g>
+</svg>
+
<p>The Windows function returns all slices, or contiguous subarrays, with shape (well, shape prefix) <code><span class='Value'>𝕨</span></code> from <code><span class='Value'>𝕩</span></code>. It might also be seen as sliding a moving window along <code><span class='Value'>𝕩</span></code>.</p>
<p>This function replaces APL's Windowed Reduction, J's more general Infix operator, and Dyalog APL's Stencil, which is adapted from one case of J's Cut operator. In BQN, it's strongly preferred to use functions, and not modifiers, for array manipulation. Functions are simpler with fewer moving parts, and more concrete, since the array results can always be viewed right away.</p>
<h2 id="basic-case"><a class="header" href="#basic-case">Basic case</a></h2>