Section9.4

]>
Book Contents Previous Section 9.3 BasicOperator Next Section 9.5 BinarySearchTree Book Index

## 9.4 BinaryExpansion

All rational numbers have repeating binary expansions. Operations to access the individual bits of a binary expansion can be obtained by converting the value to RadixExpansion(2). More examples of expansions are available in DecimalExpansionXmpPage , HexadecimalExpansionXmpPage , and RadixExpansionXmpPage .

The expansion (of type BinaryExpansion) of a rational number is returned by the binarybinaryBinaryExpansion operation.

r := binary(22/7)

11. 001‾

Type: BinaryExpansion

Arithmetic is exact.

r + binary(6/7)

100

Type: BinaryExpansion

The period of the expansion can be short or long ...

[binary(1/i) for i in 102..106]

[0. 0 00000101‾,0. 000000100111110001000101100101111001110010010101001‾,0. 000 000100111011‾,0. 000000100111‾,0. 0 0000010011010100100001110011111011001010110111100011‾]

Type: List BinaryExpansion

or very long.

binary(1/1007)

0. 000000000100000100010100100101111000001111110000101111110010110001111101‾000100111001001100110001100100101010111101101001100000000110000110011110‾111000110100010111101001000111101100001010111011100111010101110011001010‾010111000000011100011110010000001001001001101110010101001110100011011101‾101011100010010000011001011011000000101100101111100010100000101010101101‾011000001101101110100101011111110101110101001100100001010011011000100110‾001000100001000011000111010011110001‾

Type: BinaryExpansion

These numbers are bona fide algebraic objects.

p := binary(1/4)*x**2 + binary(2/3)*x + binary(4/9)

0. 01 x 2+0. 10‾x+0. 011100‾

Type: Polynomial BinaryExpansion
q := D(p, x)

0. 1 x+0. 10‾

Type: Polynomial BinaryExpansion
g := gcd(p, q)

x+1. 01‾

Type: Polynomial BinaryExpansion
Book Contents Previous Section 9.3 BasicOperator Next Section 9.5 BinarySearchTree Book Index