Skip to content

Instantly share code, notes, and snippets.

@xpqz
Last active July 7, 2021 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpqz/90b99e3906a2deaa002ef4cf811e9ae1 to your computer and use it in GitHub Desktop.
Save xpqz/90b99e3906a2deaa002ef4cf811e9ae1 to your computer and use it in GitHub Desktop.
Find length-3 expressions that evaluate to `0 0⍴⍬` in Dyalog APL
r←Brutus;glyphs;combo;eval
glyphs ← '0⍬+-×÷*⍟⌹○|⌈⌊⊥⊤⊣⊢=≠≤<>≥≡≢∨∧⍲⍱↑↓⊂⊃⊆⌷⍋⍒⍳⍸∊⍷∪∩~/\⌿⍀,⍪⍴⌽⊖⍉¨⍨⍣.∘⍤⍥@⌸⌺⍎⍕¯'
r←⍬
:for combo :in ,∘.,⍣2⍨glyphs
:trap 0
eval ← ⍎combo
:else
:continue
:endtrap
:if eval≡0 0⍴⍬
r,←⊂combo
:endif
:endfor
@xpqz
Copy link
Author

xpqz commented Jul 7, 2021

A CMC was posed: find shortest expression evaluating to 0 0⍴⍬ in Dyalog APL. Typing that into APLCard yields ⍬⊤⍬, but there are actually loads. The above function constructs all possible length-3 expressions from a subset of the APL glyphs, evaluates them in turn and looks for matches:

   +  -  ×  ÷  *      |            =      <  >            0          /          

We can think of all the Key ones being the same, so the interesting ones are:

  • ⍬⊤⍬
  • ⊤⍨⍬ -- same as above, really
  • f ⌸⍬ -- all the Key ones
  • ↑⍸0

@xpqz
Copy link
Author

xpqz commented Jul 7, 2021

Adam says:

@xpqz I disagree that all the Key ones are the same.
Only all the scalar operands are the same.
@xpqz ⊤⌸⍬ ⊢⌸⍬ ↑⌸⍬ (same as ↓⌸⍬) ⍷⌸⍬ ∩⌸⍬ /⌸⍬ (same as ⌿⌸⍬) ⍴⌸⍬ ⌽⌸⍬ (same as ⊖⌸⍬) are all interesting. I don't see how ⍉⌸⍬ works.
So, a blog post explaining each of these dozen approaches… Sounds like interesting reading to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment