-
Notifications
You must be signed in to change notification settings - Fork 108
Change definition of negative level (strawman) #58
Copy link
Copy link
Closed
Labels
Description
Negative level u L:(-n) will be redefined to mean "execute u within the boxed noun, on every cell that is enclosed by exactly n boxes."
Examples: u L:_1 means the same as u&.> when applied to a boxed noun.
phi=. * -.@%@~.&.q: NB. Euler's totient function
]t=. 5!:2 <'phi'
+-+-----------------------+
|*|+---------------+--+--+|
| ||+--------+-+--+|&.|q:||
| |||+--+-+-+|@|~.|| | ||
| ||||-.|@|%|| | || | ||
| |||+--+-+-+| | || | ||
| ||+--------+-+--+| | ||
| |+---------------+--+--+|
+-+-----------------------+
$L:_1 t
+-+-+
|1|3|
+-+-+
$L:_2 t
+-+-------+
|*|+-+-+-+|
| ||3|2|2||
| |+-+-+-+|
+-+-------+
$L:_3 t
+-+---------------+
|*|+-------+--+--+|
| ||+-+-+-+|&.|q:||
| |||3|1|2|| | ||
| ||+-+-+-+| | ||
| |+-------+--+--+|
+-+---------------+
As the examples illustrate, cells whose boxing level is less than n are left unchanged.
At each level, the argument(s) are inspected to see if they are ripe for processing: far enough from the top level if the level is negative, or close enough to the bottom level is level is nonnegative. If all argument(s) are ripe, the verb is executed on it(them) and the y argument is replaced with the result of the execution.
If an argument is not ripe, there are several cases:
- if an argument is not ripe, contains no boxes, and its required level is negative, execution along that branch terminates, because the argument will never become ripe along the branch. If the argument is y, the current value of the argument remains unchanged (as in the example above); if the argument is x, the cell is deleted from the result.
- otherwise, if all arguments are not ripe, each argument-atom is opened and processing continues on each argument-atom contents. If the arguments have different shapes, atoms are repeated as if this open-and-recur step were executed with rank 0. During the recursion, the test for ripeness of a negative-level argument uses the depth of the cell in the original argument.
- otherwise, exactly one argument must be unripe. The atoms of the unripe argument are opened and processed, with the ripe argument (whose required level must be nonnegative) being unchanged and repeated in its entirety for each opened atom of the unripe argument.
-- @HenryHRich 20:56, 22 July 2018 (UTC)
Reactions are currently unavailable