Number bases

I. Cnop
Vrije Universiteit Brussel
icnop@vub.ac.be

An example of List programming.

We present a simple example of list programming in  Mathematica .

List programming a change of basis.

Take the decimal representation of a large number

t = (3^200)

The of the logaritm tells us how many digits we have (after rounding upwards)

Log[10. , t]

This one has a simple expression in base  3  form:

BaseForm[t, 3]

Log[3, t]

with  200  zeroes. It gets shorter if we use a bigger basis:

BaseForm[t, 17]

Log[17. , t]

with only 78 digits, and less in larger basis forms.

BaseForm[t, 35]

BaseForm[t, 47]

We no longer have a sufficient number of characters at our disposal to represent all 47 digits, since the maximum is  (10 + 26).

BaseForm[t, 243]

Here we now the answer by hand: it should be a 1 followed by 40 zeroes. (Why?)

Conversion to a new "basis"

basis = 17

Clear[nextentry]

\(nextentry[{l_List, m_Integer}] := 
	
      If[m == 0, {l, 
          m}, 
		{Prepend[l, Mod[m, basis]], \((m - Mod[m, basis])\)/
            basis}]\)

The first remainder is recorded and we continue with the quotient

nextentry[{{}, t}]

nextentry[nextentry[{{}, t}]]

nextentry[nextentry[nextentry[{{}, t}]]]

nextentry[nextentry[nextentry[nextentry[{{}, t}]]]]

The expected length of the final result is the logarithm up to one more nextentry:

message = 
      First[Nest[nextentry, {{}, t}, 
          IntegerPart[Log[basis, t]] + 1]]

Instead of using logarithms we could also build a If structure to end the computiation.

Control

(basis^Range)[0, Length[%] - 1] . Reverse[message]

% == t

Try this

basis=47

nextentry[{{}, t}]

message = 
      First[Nest[nextentry, {{}, t}, 
          IntegerPart[Log[basis, t]] + 1]]

(basis^Range)[0, Length[%] - 1] . Reverse[message]

basis=243

nextentry[{{}, t}]

message = 
      First[Nest[nextentry, {{}, t}, 
          IntegerPart[Log[basis, t]] + 1]]

(basis^Range)[0, Length[%] - 1] . Reverse[message]

basis=1234567890123456789

nextentry[{{}, t}]

message = 
      First[Nest[nextentry, {{}, t}, 
          IntegerPart[Log[basis, t]] + 1]]

(basis^Range)[0, Length[%] - 1] . Reverse[message]