Notes

Chapter 4: Systems Based on Numbers

Section 1: The Notion of Numbers


Implementation of digit sequences

A whole number n can be converted to a sequence of digits in base k using IntegerDigits[n,k] or (see also page 1094)

Reverse[Mod[NestWhileList[Floor[#/k] &, n, # >=k &], k]]

and from a sequence of digits using FromDigits[list,k] or

Fold[(k #1 + #2)&, 0, list]

For a number x between 0 and 1, the first m digits in its digit sequence in base k are given by RealDigits[x, k, m] or

Floor[k NestList[Mod[k #, 1]&, x, m-1]]

and from these digits one can reconstruct an approximation to the number using FromDigits[{list, 0}, k] or

Fold[(#1/k + #2)&, 0, Reverse[list]]/k


From Stephen Wolfram: A New Kind of Science [citation]