9.15 DecimalExpansion

All rationals have repeating decimal expansions. Operations to access the individual digits of a decimal expansion can be obtained by converting the value to RadixExpansion(10). More examples of expansions are available in BinaryExpansionXmpPage , HexadecimalExpansionXmpPage , and RadixExpansionXmpPage .

The operation decimaldecimalDecimalExpansion is used to create this expansion of type DecimalExpansion.

r := decimal(22/7)
\[\]
3.142857‾

Type: DecimalExpansion

Arithmetic is exact.

r + decimal(6/7)
\[\]
4

Type: DecimalExpansion

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

[decimal(1/i) for i in 350..354]
\[\]
[0.00285714‾,0.002849‾,0.0028409‾,0.00283286118980169971671388101983‾,0.00282485875706214689265536723163841807909604519774011299435‾]

Type: List DecimalExpansion

or very long.

decimal(1/2049)
\[\]
0.000488042947779404587603709126403123474865788189360663738408979990239‾141044411908247925817471937530502684236212786725231820400195217179111‾761835041483650561249389946315275744265495363591996095656417764763299‾170326988775012201073694485114690092728160078086871644704734016593460‾22449975597852611029770619814543679843826256710590531966813079551‾

Type: DecimalExpansion

These numbers are bona fide algebraic objects.

p := decimal(1/4)*x^2 + decimal(2/3)*x + decimal(4/9)
\[\]
0.25x2+0.6‾x+0.4‾

Type: Polynomial DecimalExpansion

q := differentiate(p, x)
\[\]
0.5x+0.6‾

Type: Polynomial DecimalExpansion

g := gcd(p, q)
\[\]
x+1.3‾

Type: Polynomial DecimalExpansion