Left and right operand

General APL language issues

Left and right operand

Postby jmosk on Wed Jan 24, 2024 7:53 pm

I am confused over the use of ⍺⍺ and ⍵⍵. Can someone please explain this as the manual is confusing and the examples do not clear it up. Maybe a couple of simple examples would make it easier to understand when one would use this.
+←--------------------------------------------------------------→
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
User avatar
jmosk
 
Posts: 69
Joined: Thu Jul 18, 2013 5:15 am

Re: Left and right operand

Postby RichardP|Dyalog on Thu Jan 25, 2024 8:23 am

⍺⍺ and ⍵⍵ are the operands of a Dop. Where a Dfn is a function denoted by curly braces and the use of ⍺ and ⍵ to refer to the left and right arguments, a Dop is an operator denoted by curly braces, the use of ⍺⍺ and ⍵⍵ to refer to the left and right operands.

An operator binds to its operands to create a derived function. This derived function is then applied to arguments in an expression.

A simple example is to recreate the dyadic use of the over operator as a Dop.

Code: Select all
      _Over_ ← {(⍵⍵ ⍺) ⍺⍺ ⍵⍵ ⍵}

      2 4 6 +⍥÷ 1 2 3
1.5 0.75 0.5

      2 4 6 +_Over_÷ 1 2 3
1.5 0.75 0.5


So here ⍺⍺ refers to the left operand function, which is + in this case. The right operand function ÷ is referred to using ⍵⍵. First we take the inverse of the arguments by applying ⍵⍵ monadically, then we apply ⍺⍺ between those inverted arguments.

Note that we still need to refer to the arguments ⍺ and ⍵ of the derived function in order to specify how our operator behaves.

Operands can be arrays as well, as seen in the case of the rank operator and the power operator.

Code: Select all
(+⌿⍤2)   ⍝ Sum down the columns of sub-matrices
(+⌿⍣3)   ⍝ Sum 3 times - equivalent to +⌿+⌿+⌿
RichardP|Dyalog
 
Posts: 33
Joined: Fri Oct 12, 2018 3:05 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest