(muse:
APL Numbers
¯¯¯¯¯¯¯¯¯¯¯
Classic APL recognises only "numbers"; it has no interest in their internal
representation in binary integer or floating point form.
Sometimes confused with this internal data type, is the fact that some prim-
itive functions have restricted argument domains. For example, the "Boolean"
functions ∧ ∨ ⍲ ⍱ take only arrays of numbers in the set 0 1; the items of
the left argument of reshape (⍴) must be "natural" (non-negative, whole)
numbers 0 1 2 ...; and the relational functions < ≤ ≥ > take only those
numbers whose imaginary part is 0. We can see this distinction with express-
ions such as:
1 ∧ 2.5-3÷2 ⍝ right argument of ∧ is 0 or 1
1
(-¯3) ⍴ 3 ⍝ left argument of ⍴ is non-negative whole number
3 3 3
As a thought experiment, we could propose an APL that supported only ration-
al, or even only whole, numbers. In the latter case, 21÷3 would return 7 but
21÷2 would generate a domain error. This is analogous to an APL that doesn't
provide complex numbers, where ¯1*÷3 returns ¯1 but where ¯1*÷2 is a domain
error.
This brings to mind the sequence of generalisation:
N ⊂ Z ⊂ Q ⊂ R ⊂ C ⊂ H ⊂ O.
Prefacing this list with B, the boolean numbers 0 and 1, gives:
B Booleans: 0 1 ⍝ Boole G. 1815-1864
⊂ N Natural numbers: 0 1 2 ...
⊂ Z Integers: ... ¯2 ¯1 0 1 2 ...
⊂ Q Rationals: (4÷3) (¯7÷13) ...
⊂ R Reals: (*1) (○1) (2*÷2) ...
⊂ C Complex: 3j4 (¯1*÷2) ...
⊂ H Quaternions ⍝ Hamilton W.R. 1805-1865
⊂ O Octonions ⍝ Graves J.T. 1806-1870
At each step, we gain generality in exchange for some loss of structure. For
example, going from R to C to H to O, we lose respectively: ordering, comm-
utativity and associativity.
This table illustrates the capabilities of an APL system for each of the in-
creasingly general number systems:
┌───┬───┬───┬───┬───┬───┐
│ B │ N │ Z │ Q │ R │ C │
┌───────┼───┼───┼───┼───┼───┼───┤
│ 0∨1 │ Y │ Y │ Y │ Y │ * │ * │
├───────┼───┼───┼───┼───┼───┼───┤
│ 2+3 │ - │ Y │ Y │ Y │ Y │ Y │
├───────┼───┼───┼───┼───┼───┼───┤
│ 2-3 │ - │ - │ Y │ Y │ Y │ Y │
├───────┼───┼───┼───┼───┼───┼───┤
│ 2÷3 │ - │ - │ - │ Y │ Y │ Y │
├───────┼───┼───┼───┼───┼───┼───┤
│ 2*÷2 │ - │ - │ - │ - │ Y │ Y │
├───────┼───┼───┼───┼───┼───┼───┤
│ ¯1*÷2 │ - │ - │ - │ - │ - │ Y │
└───────┴───┴───┴───┴───┴───┴───┘
* GCD (→gcd←) is not meaningful for irrational numbers. In order to provide
GCD/LCM for its internal floating-point numbers, Dyalog uses as many terms
of their continued fraction (→cfract←) expansion as necessary to produce a
tolerably close rational approximation.
N http://en.wikipedia.org/wiki/Natural_number →nats←
Z http://en.wikipedia.org/wiki/Integer
Q http://en.wikipedia.org/wiki/Rational_number →rats←
R http://en.wikipedia.org/wiki/Real_number
C http://en.wikipedia.org/wiki/Complex_number →cxdraw←
H http://en.wikipedia.org/wiki/Quaternion →H←
O http://en.wikipedia.org/wiki/Octonian
http://en.wikipedia.org/wiki/Sedenion
)
Back to: contents
Back to: Workspaces