It possible to expand numbers in general bases.

Here we expand 111 in base 5. This means

111::RadixExpansion(5)


 421

You can expand fractions to form repeating expansions.

(5/24)::RadixExpansion(2)


 0.00110‾

(5/24)::RadixExpansion(3)


 0.012‾

(5/24)::RadixExpansion(8)


 0.152‾

(5/24)::RadixExpansion(10)


 0.2083‾

For bases from 11 to 36 the letters A through Z are used.

(5/24)::RadixExpansion(12)


 0.26

(5/24)::RadixExpansion(16)


 0.35‾

(5/24)::RadixExpansion(36)


 0.7I

For bases greater than 36, the ragits are separated by blanks.

(5/24)::RadixExpansion(38)


 0.734312512‾

The RadixExpansion type provides operations to obtain the individual ragits. Here is a rational number in base 8.

a := (76543/210)::RadixExpansion(8)


 554.37307‾

The operation wholeRagitswholeRagitsRadixExpansion returns a list of the ragits for the integral part of the number.

w := wholeRagits a


 [5,5,4]

Type: List Integer

The operations prefixRagitsprefixRagitsRadixExpansion and cycleRagitscycleRagitsRadixExpansion return lists of the initial and repeating ragits in the fractional part of the number.

f0 := prefixRagits a


 [3]

Type: List Integer

f1 := cycleRagits a


 [7,3,0,7]

Type: List Integer

You can construct any radix expansion by giving the whole, prefix and cycle parts. The declaration is necessary to let FriCAS know the base of the ragits.

u:RadixExpansion(8):=wholeRadix(w)+fractRadix(f0,f1)


 554.37307‾

If there is no repeating part, then the list [0] should be used.

v: RadixExpansion(12) := fractRadix([1,2,3,11], [0])


 0.123B0‾

If you are not interested in the repeating nature of the expansion, an infinite stream of ragits can be obtained using fractRagitsfractRagitsRadixExpansion.

fractRagits(u)


 [3,7,3,0,7,7‾]

Type: Stream Integer

Of course, it’s possible to recover the fraction representation:

a :: Fraction(Integer)


 76543210

Type: Fraction Integer

More examples of expansions are available in DecimalExpansionXmpPage , BinaryExpansionXmpPage , and HexadecimalExpansionXmpPage .