News for hackers. Stuff that matters.
Re:Inventing an Operation to Solve x^x = y (2000) by xelxebar on Thursday November 28, 2019 @09:17PM (#21661488)
Essentially, yes.

> (^~^:_1) 5

First, let me break this down, in the interest of sharing the joys of J.

The thing in parenthesis is our inverse operation of x^x; we then evaluate that at 5. The first ^ is exponentiation and the following ~ makes binary operators into unary ones by evaluating on the diagonal. In other words it turns f(x,y) into f(x) = f(x,x), which for x^y corresponds to x^x.

Next we have the ^: modifier. This is function iteration, i.e. exponentiation over function composition. The function is on the left (here ^~) and the count on the right (here _1). So f ^: 2 means f(f(x)). In fact, this function exponentiation is extended to negative integers as well! In J, negative numbers are prefixed with _ (underscore), and f^:_1 actually gives us the inverse of f (if it exists)!

Anyway, we can see inspect the definition for an operation's inverse using the b. verb. From the jconsole:

        ^~ b. _1
    3 : '(- -&b@(*^.) % >:@^.)^:_ ]1>.b=.^.y'"0 :.(^~)
The part we are interested in is in single quotes. Pulling this one apart would involve introducing the various operator combinators in J, so suffice it to say that the ^:_ part numerically approximates a fixed point of the part in parenthesis, which essentially is a straightforward transcription of the recursive relation in Newton's method.

There are no comments on this comment yet.