Index   <<   >>

Things for 2

It is useful, especially in a functional programming language, to replace as many dyads which habitually use a constant as one argument, with monads defined in terms of that constant argument.

The number 2 occurs in various contexts in J. Here we discuss the family denoted by the : cases of + - * % .

+: is the “double”, or “times 2” verb

   +: _1.5 0 3.25 4
_3 0 6.5 8 

-: is the “halve:” or “divide by 2” verb

   -: _1.5 0 3.25 4
_0.75 0 1.625 2

*: is the “square”, or “power 2” verb

   *: _1.5 0 3.25 4
2.25 0 10.5625 16

%: is the “square root” or “root 2” verb

   %: _1.5 0 3.25 4
0j1.22474 0 1.80278 2

Tow more 2-related verbs are the monads #. (2 base value) and its inverse #: (base 2 representation)

   #. 1 0 1 0 1,:1 1 1 0 0
21 28
   #: 21 28
1 0 1 0 1
1 1 1 0 0