Index   <<   >>

Isn’t that the limit?

Sometimes you don’t know many times you want to apply a verb, as long as you eventually get the answer. In J you can convert the power conjunction (^:) into limit adverb by specifying that the number of times the verb is to be applied is infinite (^:_ ) — that is, until the result is the same as the previous result. Suppose we create the limit adverb:

   L=.^:_

The transitive closure of logical table can be obtained by repeated uses of table as left argument of the logical inner product with the developing result:

   lip=.+./ .*. NB. logical inner product
   ]T=.6 6$1 1 0 0 0 0 0
1 1 0 0 0 0
0 1 1 0 0 0
0 0 1 1 0 0
0 0 0 1 1 0
0 0 0 0 1 1
0 0 0 0 0 1
   T&lip L T
1 1 1 1 1 1
0 1 1 1 1 1
0 0 1 1 1 1
0 0 0 1 1 1
0 0 0 0 1 1
0 0 0 0 0 1

(Fix matrix products must be computed to determine closure.)

Going back to the example from If had the power, we can apply the limit adverb to halve repeatedly until all even factors are removed:

   halve if even L 160
5