Arrow

NAME

Math::Arrow - Handle Knuth-style arrow notation

SYNOPSIS

In Knuth arrow notation, one arrow is simple exponentiation:

2 ā†‘ 3 # gives 8

Every additional arrow in the operator implies a layer of reduction of the form:

a ā†‘{n number of ā†‘'s} b =
        a ā†‘{n-1 ā†‘'s} ( a ā†‘{n-1 ā†‘'s (... a)...)

where there are b number of as in the second form.

But this module only implements up to five arrows (really, if you need more than five, I question what the hell you think Perl is going to do for you...)

More concretely:

4 ā†‘ā†‘ā†‘ā†‘ 3 =
    4 ā†‘ā†‘ā†‘ ( 4 ā†‘ā†‘ā†‘ 4 ) =
    4 ā†‘ā†‘ā†‘ ( 4 ā†‘ā†‘ ( 4 ā†‘ā†‘ ( 4 ā†‘ā†‘ 4 ))) =
    4 ā†‘ā†‘ā†‘ ( 4 ā†‘ā†‘ ( 4 ā†‘ā†‘ ( 4 ā†‘ (4 ā†‘ (4 ā†‘ 4 ))))) =
    4 ā†‘ā†‘ā†‘ ( 4 ā†‘ā†‘ ( 4 ā†‘ā†‘ ( 4 ** 4 ** 4 ** 4))) = ...

As you can see, this quickly gets out of hand. In fact, there are very few arrow-notation expressions which can be evaluated in a practical period of time (the above example would take longer to fully evaluate than the universe has been around, even on the fastest computers available, today.

Probably the best-known arrow-notation example is Graham's Number (G) which is defined as:

$g1 = 3 ā†‘ā†‘ā†‘ā†‘ 3;
    $g2 = arrow(3, 3, $g1);
    ...
    $g64 = arrow(3, 3, $g63);
    use constant G = $g64;

operator ā†‘

The ā†‘ operator is an infix operator which is equivalent to arrow(left-hand-side, right-hand-side, 1) and ** and performs simple exponentiation. It is right-associative, just like **.

operator ā†‘ā†‘

The ā†‘ā†‘ operator is also a right-associative infix operator and is equivalent to arrow(lhs, rhs, 2).

operator ā†‘ā†‘ā†‘

See ā†‘ā†‘ for details. Equivalent to arrow(lhs, rhs, 3).

operator ā†‘ā†‘ā†‘ā†‘

See ā†‘ā†‘ for details. Equivalent to arrow(lhs, rhs, 4).

operator ā†‘ā†‘ā†‘ā†‘ā†‘

See <ā†‘ā†‘> for details. Equivalent to arrow(lhs, rhs, 5).

arrow($a, $b, $arrows)

Returns the arrow-notation expansion for $a ā†‘[$arrows] $b where ā†‘[$arrows] denotes $arrows many ā†‘ in the final operator. Thus these two are equivalent:

arrow(3, 3, 4) == (3 ā†‘ā†‘ā†‘ā†‘ 3)

term G

(only exported via the :constants tag)

The value G is defined as a more-or-less humorous element of this module. It can never be used for anything practical, as evaluating its value would take such a mind-bogglingly large amount of time and memory that you might as well simply shoot your computer. But... don't do that.

This value is Graham's number, defined as described above.

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.