TSa Thomas.Sandlass-at-barco.com |Perl 6| wrote:
Firstly, shouldn't there also be infinite strings? E.g. 'ab' x Inf
is a regularly infinite string and ~pi as well. Other classes might
have elaborate notions of infinity.
A string whose length is Inf is not itself equal to Inf. But $s.chars >
$b would be true for all normal values of the Num b.
The Complex e.g. might have an
angle associated to an Inf.
I think there are too many different ways of doing that to make it built
in. Normal Complex numbers are not ordered. But as described, a
complex number "but Inf" will still be greater than any normal complex
number.
Just as real numbers are pretty basic, you can add Inf to that domain to
form *"affinely extended real number system", which is what I think the
IEEE floats model a finite precision subset of. But there are many ways
to extend the basic, and someone using such a system would need to use a
module or define his own to get the exact behavior wanted.*
Secondly, you only have a single Inf constant and its negation. But
there should be a multitude of infinities. E.g. a code fragment
my Int $a = random(0..1) > 0.5 ?? 3 !! Inf;
my Int $b = $a + 1;
say "yes" if $b > $a;
should always print "yes". That is we continue counting after Inf such
that we have transfinite ordinals.
0, 1, 2, ..., Inf, Inf+1, Inf+2, ..., Inf*2, Inf*2+1, ...
Inf + $n == Inf for all real numbers $n. You don't get different
infinities that way. Likewise for multiplication: 2*Inf or even Inf**2
is still the _same_ value Inf.
The proposed Infinite class (see the thread I started on 4/25/2008) does
handle transfinite cardinals. Nothing in the P6 standard library cares
whether you mean the number of integers or the number of real numbers
etc. except for comparing Infinite values directly. But basic support
is available for that in the class, and more specialized applications
can write functions that use those values or extend the class to the
desired domain.
The implementation is strait forward as an array of coefficients
of the Inf powers with Inf**0 == 1 being the finite Ints. The sign
bit goes separate from the magnitude. That is you can do the usual
Int arithmetic in the ranges Inf..^Inf*2 and -Inf*2^..-Inf except
that Inf has no predecessor and -Inf no successor. Well, and we lose
commutativity of + and *. I.e. 1 + $a != $a + 1 if $a is transfinite.
What?
A power series of Inf is just the same Inf.
Were you trying to remember something concerning a power _set_?
I'm not sure if such a concept of "interesting values of infinity"
is overly useful, though. In TeX e.g. there are infinitely stretchable
spacings of different infinitudes so that they overwrite each other.
That kind of light-duty use (not mathematically rigorous but easy to
represent TeX's two springs) is why I included transfinite ordinals in
the class.
Also I think we can have finite conceptual infinities for types like
int32 and num64. In the latter case we also have infinitely small
values and "infinities" like sqrt(2). In short everything that falls
out of the finite range of these types and is captured in Int or Num.
The domain of int32 is a finite subset of \mathbb{Z}. If you want to
reserve some of the bit representations to mean other things, define
another type. The point of the lower-case types is to do the native CPU
stuff.
num64, assuming IEEE semantics, will include special values for + and -
Inf and for underflows like you indicate. I suppose that the
implementation of Num will use the underlying bit representations when
you convert Inf to Num. The Int type also is defined as being able to
represent + and - Inf, and the implementation will need to flag it as
such, somehow.
BTW, with an infinite precision Num I see no need for the Rat type!
The Num type is not infinite precision, but the highest-precision native
type that operates at full speed. Since there are high or arbitrary
precision float libraries available now, I'm sure CPAN6 will include some.
--John