Friday, 26 August 2016

Endless Exponentiation

endless iteror #4

Exponentiation

Frances K*, 2016

Learn to create ever bigger numbers
in an article series on site and blog,
dedicated to Chelsea Manning hero.

© Kreative commons

#4 Exponentiation

We reduce various powers step by step to series of multiplications. Star powers will be supported by pop marks instead of brackets.

4.1 Multiple repetitions

The concept of repeating a repetition operation, which defines exponentiation, is easily confused with the double repetition of a number, which equals two multiplications.
If number n is a length, and you multiply that once for a plane, or twice to measure a volume, then exponentiation sizes up to any number of dimensions.

To multiply a number by itself n*n is a square n2 or 2nd power, which we notate in the formats:
n^2 or n**2 or 2**n or n**2
Next multiplication n*n*n forms a cube n3 or 3d power:
n^3 or n**3 or 3**n or n**3
These formats depend on the method of evaluation to apply, and sometimes we may switch =: between them.

In a mixed context the operand position should be clear from the code alone, not the colours. We delimit a left evaluated operation by a plus + or pluses ++ at the top. And strictly, subspace prefix + is defined for right iterators, and prefix ++ indicates left iterators.

To repeatedly multiply a number by itself is called exponentiation or powers nr in general. A command line expression doesn't allow superscripts, but we automate powers in four formats:

n^r or n**r or
++r**n or +n**r

In each format a different method reduces through suboperations to number. We will explain them in historical order.

Then little Joey, the US treasury, astronomers, and mighty Joe in the multiverse, can create @ll the large numbers they need.

10^3 = 10*10^2 = 10*10*10^1
     = 10*10*10 = 1000

1000**5 = (10**3)**5 = 10**3*5
     = 10**15 = 1000000000000000
        =: 1,000,000,000,000,000

++2**+2***10 = ++2**10**+1***10
 ++2**10**10 = ++100**10
   =: 10^100 =: 1E100    googol

+10**(10**100)
    =: +2+*10***3
     = +10**2+*10***2
     = +10**100+*10***1
          =: 10^10^100
          =: EEE2     googolplex

The blue star ** is so powerful: right iterator, left evaluation, that it only accepts single operation input. The red star ** with left iterator and left evaluation subspace, is our all-round red riding hood.

4.2 Caret powers

A caret ^ is the ascii sign for powers or exponentiation, but programmers may use a double star ** in a similar way.
The usual ^ powers have precedence over * multiplication.

Define exponentiation by a single multiplication step, then iterate == over that to form a series of multilications.
To show examples, click @t the board.

@

n^(r+1) = n*n^r
       == n*..n^1 :r
        = n*..n :r

5^(2+1) = 5*5^2
       == 5*..5^1 :2
        = 5*..5 :2

5^(2+1) = 5*5^2
       == 5*5*5^1
        = 5*5*5 = 125

4^(3+1) = 4*4^3
       == 4*..4^1 :3
        = 4*..4 :3

4^(3+1) = 4*4^3
       == 4*4*4*4^1
        = 4*4*4*4 = 256

2^(9+1) = 2*2^9
       == 2*..2^1 :9
        = 2*..2 :9

2^(9+1) = 2*2^9
 == 2*2*2*2*2*2*2*2*2*2^1
  = 2*2*2*2*2*2*2*2*2*2 = 1024

We don't follow the custom from physics, where you multiply without an operator sign, as if this empty ^{0} does nothing.
We feel that addition of unary numbers mn is the true void operator, first comes multiplication, and next recursions are enumerated from there: counting *{s} stars.

Operators with multiple carets ^.. evolved from the arrow functions .. invented by Donald Knuth, who is an expert in algorithms for computers. Knuth's superexponential operators are also called up-arrows, but nowadays only the arrowhead or caret remains.
In a short article in 1976 Knuth invented his arrows to show that finite numbers can get extremely large, and therefore we should consider them just as interesting as infinite numbers. Quite a statement from a man who injected infinity in the real field with his surreal numbers.

Multiple carets ^.. are ruled by right majority precedence. So major operations with more carets are reduced to number first, and adjacent equal operators are worked away from the right.
For variety between operators and to save on brackets, you can use them together and evaluate majority carets before minority stars.

4.3 Minority star powers

Now describe star operations *.. ruled by minority precedence, where lesser stars are reduced to number first.

a**b*c = a**(b*c)
a*b**c = (a*b)**c

Because zero stars *{0} is a virtual operator for direct addition, it is consistent to evaluate smaller operators sooner.

In this section we apply right minority precedence. So operations with equal stars are worked out rtl (from right to left).

a**b**c = a**(b**c)

We paint right minority stars black by default (with a blue accent inside brackets).

Evaluating these operations stepwise, a preceding suboperation is spawned on the right, and this immediately gets precedence. We work it out on top, before completing the whole subtower.
For example the power n**r has to wait inactivated until its first suboperation n*n produces a number p, that then becomes the iterator for a new suboperation n*p etc.

But we have to take care to shield off the iterator r in the original operation from the resulting p of the suboperations.
To separate operations we introduce pop marks + that postpone operations, and function like temporary brackets. A pop +* waits and separates the sub from the super space.

Define minority star exponentiation ** by its multiplication * step, using left pops +* that express a factor on top.

@

n**r1 = n**r+*n
n**r1+*p = n**r+*n*p
n**1+*p = n*p

3**111 = 3**11+*3
3**11+*3 = 3**1+*3*3
3**1+*9 = 3*9 = 27
2**6 = 2**5+*2
2**3+*8 = 2**2+*2*8
2**1+*32 = 2*32 = 64

The postponed operation +* with its iterator p waits for the next factor n to come free. Then n*p shifts on top and has precedence.

We use a left pop +* to shield the original exponent from the suboperations issued on the right.
By introducing, shifting and eliminating pops we can evaluate superexponents using a minimum of signs (without brackets).

4.4 Leftist star powers

In expressions like a*b**c**d*e the rule of right minority precedence champions the largest numbers. But because exponents matter most, the results of straight rtl top down evaluation are almost as big.

a*(b^(c^(d*e))) <≈ (a*b)^(c^(d*e))

Now we'd like to evaluate operators without the use of precedence rules. Operators can become so big and complex that it's not so straightforward to compare them in size anymore.
Also we'd rather do without inner expressions in (group) brackets.

The alternative is to scan expressions ltr, and to apply rewrite rules strictly from left to right. This way we won't meet difficult precedence choices during evaluation.
Our leftist powers r**n are quite revolutionary: with the usual operands reversed and suboperations issued on the left.

Operators are painted red, when the iterator operand is placed left. But if operand position doesn't matter, because iterator and item happen to be n**n equal, or for commutative r*n multiplication, we let stars have the normal colour.

Define red star powers by working out := multiplications pi*n on the left. Click @ for examples.

@

2r**n = n*+1r**n
      = p1*n*+r**n where p1=n
   := p2*+r**n    where p2=n*n
   == pr1*+1**n  where pr1=n..*n r:
    = pr1*n
   := pr2 = n.*n.. :r1 for  r0
& 1**n = n = 1*n
<=> r**n = 1.*n.. :r for  r>0

11111**2 = 2*+1111**2
     = 2*2*+111**2
    := 4*+111**2
    == 16*+1**2
     = 16*2
    := 32

6**3 = 3*+5**3
     = 3*3*+4**3
    := 9*+4**3
    == 243*+1**3
     = 243*3
    := 729

8**8 = 8*+7**8
    := 64*+6**8
    == 2097152*+1**8
    := 16777216
     1.7E7

Moving ltr a suboperation is reduced to number first, before the next is issued. We use right pops *+ to keep the subroutines separated from the original iterator.
Semi-permeable bracketing by pops is crucial in the event a subtotal := pi is ready and the superoperation r**n is decremented again. The formerly postponed operator then shifts and becomes active with a new item *n to repeat, and the next pop *+ is put in place to stand guard.

Berlin 1910, lady mason on a ladder high above a smokey city