aboutsummaryrefslogtreecommitdiff
path: root/src/hyper/pages/RADIX.ht
blob: cffd36300be479b85ba99fc03ade9a6dccb44128 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved.
% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
\newcommand{\RadixExpansionXmpTitle}{RadixExpansion}
\newcommand{\RadixExpansionXmpNumber}{9.65}
%
% =====================================================================
\begin{page}{RadixExpansionXmpPage}{9.65 RadixExpansion}
% =====================================================================
\beginscroll

It possible to expand numbers in general bases.

\labelSpace{2pc}
\xtc{
Here we expand \spad{111} in base \spad{5}.
This means
\texht{$10^2+10^1+10^0 = 4 \cdot 5^2+2 \cdot 5^1 + 5^0.$}{%
\spad{10**2+10**1+10**0 = 4*5**2+2*5**1+5**0.}}
}{
\spadpaste{111::RadixExpansion(5)}
}

\xtc{
You can expand fractions to form repeating expansions.
}{
\spadpaste{(5/24)::RadixExpansion(2)}
}
\xtc{
}{
\spadpaste{(5/24)::RadixExpansion(3)}
}
\xtc{
}{
\spadpaste{(5/24)::RadixExpansion(8)}
}
\xtc{
}{
\spadpaste{(5/24)::RadixExpansion(10)}
}
\xtc{
For bases from 11 to 36 the letters A through Z are used.
}{
\spadpaste{(5/24)::RadixExpansion(12)}
}
\xtc{
}{
\spadpaste{(5/24)::RadixExpansion(16)}
}
\xtc{
}{
\spadpaste{(5/24)::RadixExpansion(36)}
}
\xtc{
For bases greater than 36, the ragits are separated by blanks.
}{
\spadpaste{(5/24)::RadixExpansion(38)}
}
\xtc{
The \spadtype{RadixExpansion} type provides operations to obtain the
individual ragits.
Here is a rational number in base \spad{8}.
}{
\spadpaste{a := (76543/210)::RadixExpansion(8) \bound{a}}
}
\xtc{
The operation \spadfunFrom{wholeRagits}{RadixExpansion} returns a list of the
ragits for the integral part of the number.
}{
\spadpaste{w := wholeRagits a \free{a}\bound{w}}
}
\xtc{
The operations \spadfunFrom{prefixRagits}{RadixExpansion} and \spadfunFrom{cycleRagits}{RadixExpansion}
return lists of the initial and repeating ragits in the
fractional part of the number.
}{
\spadpaste{f0 := prefixRagits a \free{a}\bound{f0}}
}
\xtc{
}{
\spadpaste{f1 := cycleRagits a \free{a}\bound{f1}}
}
\xtc{
You can construct any radix expansion by giving the
whole, prefix and cycle parts.
The declaration is necessary to let \Language{}
know the base of the ragits.
}{
\spadpaste{u:RadixExpansion(8):=wholeRadix(w)+fractRadix(f0,f1) \free{w f0 f1}\bound{u}}
}
\xtc{
If there is no repeating part, then the list \spad{[0]} should be used.
}{
\spadpaste{v: RadixExpansion(12) := fractRadix([1,2,3,11], [0]) \bound{v}}
}
\xtc{
If you are not interested in the repeating nature of the expansion,
an infinite stream of ragits can be obtained using
\spadfunFrom{fractRagits}{RadixExpansion}.
}{
\spadpaste{fractRagits(u) \free{u}}
}
\xtc{
Of course, it's possible to recover the fraction representation:
}{
\spadpaste{a :: Fraction(Integer) \free{a}}
}

\showBlurb{RadixExpansion}
More examples of expansions are available in
\downlink{`DecimalExpansion'}{DecimalExpansionXmpPage}\ignore{DecimalExpansion},
\downlink{`BinaryExpansion'}{BinaryExpansionXmpPage}\ignore{BinaryExpansion}, and
\downlink{`HexadecimalExpansion'}{HexadecimalExpansionXmpPage}\ignore{HexadecimalExpansion}.
\endscroll
\autobuttons
\end{page}
%