ProofWiki - an online compendium of mathematical proofs
The Array Cast - highlighted episodes are:
– Jeremy Howard - 1:12:51 Jeremy said, “I like to do APL study group because it’s a way of like self-selecting that small group of humanity who’s actually interested in trying new things, despite the fact that they’re grown ups. Then, try to surround myself with those people in my life”.
– Eric Iverson
– Tacit Programming
Since APL’s reduction is defined as insertion of a function between the elements of a vector followed by normal execution as APL (i.e. right-to-left), subtraction-reduction becomes alternating sum: -/a b c d ⇔ a-b-c-d ⇔ a-(b-(c-d)) ⇔ a+(-b)+c+(-d)
This means you can write pi_approx ← {4 × -/ ÷ 1 + 2×⍳⍵}
f¨ always applies to individual elements, much like + does.
To add each number from 1 2 3 to the individual rows of a matrix, you can split the matrix into a vector of vectors, then do the addition, and then mix the vector of vectors back into a matrix: ↑1 2 3 + ↓matrix
However, much better is to master the Rank Operator so you can specify that you want each scalar (element; rank-0 array) on the left paired up with each vector (row; rank-1 array) on the right: ⍤0 1 — and thus 1 2 3(+⍤0 1)matrix
I think you have a systematic problem of terminology in the notebook document. While for functions, distinguishing between monadic and dyadic is enough, this isn’t the case for operators. There are indeed two types of operators monadic and dyadic, but each of these can in turn derive a monadic or dyadic (or ambivalent!) function.
For example, when looking at ∘ you have “dyadic ∘ (Bind)” where “dyadic” refers to ∘ taking two operands, because you’re using the derived function *∘2 monadically. However, for ⍨ you have “dyadic ⍨ (commute)” where “dyadic” refers to the derived function -⍨ being applied dyadically, while ⍨ itself is a monadic operator (taking only one operand).
This leads you to miss the fact that the monadic operator ⍨ also derives a monadic function even when the operand is a function. Confusingly, both when deriving monadic and dyadic functions from ⍨ with a function operand, is ⍨ called “Commute”. I personally prefer calling the form deriving a dyadic function “swap” (as in swapping arguments) and the form deriving a monadic function “self” (as in applying an argument with itself).
Useful examples of “self” are ×⍨ for squaring and +⍨ for doubling.
While this f is indeed shy, it doesn’t compute the square of its argument. It assigns the squaring function to ff and then doesn’t return that unless the value is used, but dfns are not allowed to return functions, so we get a SYNTAX ERROR. To make a proper shy square function, do:
f ← { result ← ⍵*2 }
Now f 3 will be silent, but ⎕←f 3 or ⊢f 3 till show 9. (The only important thing is that the function ends on an assignment; the variable name used is immaterial.)
We can even create a “make shy” operator:
shy←{⍺←⊢ ⋄ r←⍺ ⍺⍺ ⍵}
2+shy 3
⊢2+shy 3
5
By the way, shy functions are very useful when the primary purpose of the function is its side effect, e.g. writing to a file.