APL study session 5

Discussion of the 5th study group can go here. Overview

[ <<< session 4 | session 6 >>> ]

This is a wiki post - feel free to edit to add links from the lesson or other useful info.


Study session resources

Study session links


I struggling to understand divide-reduce.
The plus-reduce and multiply-reduce both seem to combine the running result with the next element, but by that rule, the last divide-reduce woudl seem to be 0.5 / 3 = 0.1667 but instead it appears to have change operator from divide to multiply as 0.5 x 3 = 1.5.

So what am I missing?

This might be helpful example comparisons to understand what’s going on.

1 Like

Thanks @Enzo. Great example.

So to be descriptive, “once the divide has been distributed through the array, the resultant expression is evaluated right-to-left”

All functions in APL are evaluated right-to-left! :slight_smile:

This confuses me. The opposite is said in a few places in Session 2:

  • [38:57] “we always go right-to-left”
  • [40:04] “when i say we’re doing things right-to-left I’m only talking about functions”
  • [40:57] “the rules are different for operators but […] all functions […] go right-to-left”

In trying to clarify this, I did find the following Syntax Rules interesting:

  • Functions have long right scope : takes as its right arguments everything to their right.
  • Dyadic functions have short left scope : takes as its left arguments the first piece of data to its left.
  • Operators have long left scope : takes as its left operand the longest function to its left.

[Edit:] Reviewing the videos again…
I see the order of evaluation for the Slash Operator is explained clearly here (this just didn’t hook in my brain the first time through - maybe I was watching too late)

Trying to understand the apparent different evaluation direction between:

Reduce “/”
R is an array formed by applying function f between items of the vectors along the Kth xis of Y.

Scan “\”
R is an array formed by successive reductions along the Kth axis of Y.

I’ve a tentative notion that one way to think about this is that

  • functions go right-to-left
  • operators go left-to-right.

For example…

  • the Reduce Operator moves left-to-right inserting the function between all elements, and only after insertions completed, the functions are evaluated right-to-left.
  • the Scan Operator moves left-to-right inserting the function once, then evaluates that function right-to-left. With that result, the operator moves right inserting another single function.

Or left-to-right is just for the Scan Operator? [I’ll come back to update this when I learn more]

Apologies I mistyped - fixed now. Functions are applied right-to-left, and operators are applied left-to-right.

1 Like

Yes, it’s operating on successively larger subarrays, from left-to-right. It’s a different concept to either how multiple functions are parsed or how multiple operators are parsed.

1 Like

This I believe is just
1: dyadic result 0.5
2: monadic 3 divided into previous result i.e. 1/3
3: dyadic 4 divided in to previous result
4: monadic 5 = 0.2 divided into .375

1 Like