Stencil Lives

⎕io←0 throughout. ⎕io delenda est. Stencil A stencil operator ⌺ is available with Dyalog version 16.0. In brief, stencil is a dyadic operator f⌺s which applies f to (possibly overlapping) rectangles. The size of the rectangle and its movement are controlled by s. For example, enclosing 3-by-3 rectangles with default movements of 1: ⊢ a←4 […]

Krypto

In the 2016 Year Game, the task was to generate the numbers 0 to 100 using APL primitives and the digits 2 0 1 6 in that order. For example, 20=16 ×2016 2⌊016 2+×016 … This “puzzle of the year” brings to mind Krypto, a game I played many years ago while in grade school. […]

Stencil Maneuvers

Introduction The e-mail arrived in the early afternoon from Morten, in Finland attending the FinnAPL Forest Seminar. How do I speed this up and impress the Finns? 0 cmpx ‘e←⊃∨/0.2 edges¨r g b’ 6.4E¯1 edges {⍺←0.7 ⋄ 1 1↓¯1 ¯1↓⍺<(|EdgeDetect apply ⍵)÷1⌈(+⌿÷≢),⍵} apply {stencil←⍺ ⋄ {+/,⍵×stencil}⌺(⍴stencil)⊢⍵} EdgeDetect ¯1 ¯1 ¯1 ¯1 8 ¯1 ¯1 ¯1 […]

Calculation v Look-Up

(⎕io←0 and timings are done in Dyalog version 15.0.) Table Look-Up Some functions can be computed faster by table look-up than a more traditional and more conventional calculation. For example: b←?1e6⍴2 cmpx ‘*b’ ‘(*0 1)[b]’ *b → 1.32E¯2 | 0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕ (*0 1)[b] → 1.23E¯3 | -91% ⎕⎕⎕ Some observations about this benchmark: (a) The […]

APL Exercises

These exercises are designed to introduce APL to a high school senior adept in mathematics. The entire set of APL Exercises has the following sections: Introduction 0. Beginnings 1. Utilities 2. Recursion 3. Proofs 4. Rank Operator 5. Index-Of 6. Key Operator 7. Indexing 8. Grade and Sort 9. Power Operator 10. Arithmetic 11. Combinatorial […]

50847534

⎕io←0 throughout. I was re-reading A Mathematician’s Apology before recommending it to Suki Tekverk, our summer intern, and came across a statement that the number of primes less than 1e9 is 50847478 (§14, page 23). The function pco from the dfns workspace does computations on primes; ¯1 pco n is the number of primes less […]

Constructions

Suki Tekverk, a summer intern, spent the last two weeks here studying APL. She will be a high school senior next September and is adept in math, so in addition to APL we also considered some math problems, proofs, and proof techniques, including the following: Given line segments x and y, construct (using compass and […]

A Memo Operator

Abstract Some functions are simply stated and easily understood as multiply-recursive functions. For example, the Fibonacci numbers are {1≥⍵:⍵ ⋄ (∇ ⍵-2)+∇ ⍵-1}. A drawback of multiple recursion is abysmal performance even for moderate-sized arguments, consequently motivating resorts to circumlocutions. The memo operator addresses the performance problem and restores multiple recursion to the toolkit of […]

Shuffle Faster Please!

Andy reported that in the shuffle QA some functions take a long time: m9249   “4½ days so far” rankop  21.5 hours m12466  26.3 hours points  7.2 hours Background: Shuffle QA is an intensification of the normal QA. The suite of over 1800 QA functions is run under shuffle, whereby every getspace (memory allocation) is followed by every APL array […]

The Halting Problem Rendered in APL

The halting problem is the problem of determining, from a description of a program and an input, whether the program will finish running or continue to run forever. It was proved in the negative by Alonzo Church and Alan Turing in 1936, and can be rendered in Dyalog APL as follows: Suppose there is an […]