Index   <<   >>

Just the opposite

The concept of inverse is prominent in mathematics. Reversal and transpose are self inverse: |.|.x is x and |:|:x is x for all x . Negation is also self-inverse, that is, --x is x for all numeric x . The exponential and natural logarithm are inverses with respect to each other, that is exp ln x is ln exp x is x . The base-2 verb is inverse to the antibase-2 verb, so that #. #: x is x for all numeric x , and #:#.u is u for all boolean lists u having a leading 1 .

This leads to a nice solution to the Josephus problem, which asks what original position (origin-1) a person should stand in in order to be the last person chose when every second person is removed from a ring of people. Thus Josephus 1 is 1 , Josephus 2 is 1 , Josephus 3 is 3 , Josephus 4 is 1 , Josephus 5 is 3 , Josephus 6 is 5 , and so forth. A suitable definition for Josephus is

   Josephus=.1&|.&.#:"0
   Josephus 1 2 3 4 5 6 7 8 9 10
1 1 3 1 3 5 7 1 3 5

J knows many inverses. For example, the sum scan:

   ]y=.i.7
0 1 2 3 4 5 6
   ]q=.+/\y
0 1 3 6 10 15 21
   +/\^:_1 q
0 1 2 3 4 5 6

See the discussion of inverses in the J Dictionary, in the description of the power conjunction.