Skip to content

Commit 904de9d

Browse files
committed
[CaR Grant] Toss MidRat and ZDR normalization
- MidRat is ded[^1] - ZDR normalization is currently on back burner due to causing poorer error reporting and not solving all the mathemantical problems with ZDRs [1] http://blogs.perl.org/users/zoffix_znet/2018/05/perl-6-car-tpf-grant-monthly-report-may-2018.html
1 parent a43da68 commit 904de9d

File tree

1 file changed

+28
-82
lines changed

1 file changed

+28
-82
lines changed

doc/Language/numerics.pod6

Lines changed: 28 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ L<double-precision floating-point|https://en.wikipedia.org/wiki/Double-precision
6262
6363
A L<Num> literal is written with the exponent separated using letter C<e>. Keep
6464
in mind that letter C<e> B<is required> even if the exponent is zero, as
65-
otherwise you'll get a L<Rat> or L<MidRat> rational literal instead:
65+
otherwise you'll get a L<Rat> rational literal instead:
6666
6767
=begin code
6868
say 42e0.^name; # OUTPUT: «Num␤»
@@ -137,18 +137,19 @@ how-is-it 3+2i; # OUTPUT: «meh␤»
137137
138138
The types that do the L<Rational> role offer high-precision and
139139
arbitrary-precision decimal numbers. Since the higher the precision the
140-
larger the performance penalty, the L<Rational> types come in three flavours:
141-
L<Rat>, L<MidRat>, and L<FatRat>. The L<Rat> is the most oft-used variant
142-
that degrades into a L<Num> when it can no longer hold all of the requested
143-
precision. The L<FatRat> is the arbitrary-precision variant that keeps growing
144-
to provide all of the requested precision. Lastly, the L<MidRat> type is
145-
somewhat in-between of a L<Rat> and L<FatRat>: offering arbitrary-precision
146-
but degrading like a L<Rat>, when used in lower-precision operations.
140+
larger the performance penalty, the L<Rational> types come in two flavours:
141+
L<Rat> and L<FatRat>. The L<Rat> is the most oft-used variant
142+
that degrades into a L<Num> in most cases, when it can no longer hold all of
143+
the requested precision. The L<FatRat> is the arbitrary-precision variant that
144+
keeps growing to provide all of the requested precision.
147145
148146
=head2 C<Rat>
149147
150148
The most common of L<Rational> types. It supports rationals with denominators
151149
as large as 64 bits (after reduction of the fraction to the lowest denominator).
150+
C<Rat> objects with larger denominators can be created directly, however, when
151+
C<Rat>s with such denominators are the result of mathematical operations, they
152+
degrade to a L<Num> object.
152153
153154
The L<Rat> literals use syntax similar to L<Num> literals in many other
154155
languages, using the dot to indicate the number is a decimal:
@@ -209,29 +210,8 @@ say ½ + ⅓ + ⅝ + ⅙; # OUTPUT: «1.625␤»
209210
If a I<mathematical operation> that produces a L<Rat> answer would produce
210211
a L<Rat> with denominator larger than 64 bits, that operation would instead
211212
return a L<Num> object. When I<constructing> a L<Rat> (i.e. when it is not
212-
a result of some mathematical expression), however, in similar
213-
circumstances a L<MidRat> type is produced instead.
214-
215-
=head2 C<MidRat>
216-
217-
The L<MidRat> type is a subclass of a L<Rat>: it's used when construction of a
218-
L<Rat> object is attempted, but too much precision is requested. The L<MidRat>
219-
can hold all of the given precision, just like a L<FatRat> would, but it doesn't
220-
have the same "infectiousness" so if it's not used in high-precision operations
221-
with other L<FatRat> objects, it'll degrade to a L<Num>, just like a L<Rat>
222-
object would.
223-
224-
Attempts to I<construct> a L<Rat> with denominator larger (after reduction)
225-
than 64 bits in size produce a L<MidRat>
226-
object (L<MidRatStr> allomorph for L<RatStr> allomorph constructon). Such
227-
construction occurs when a L<Rational> literal is written in the code, the
228-
L«C<Str.Rat>|/type/Str#method_Rat» or L«C<Str.Numeric>|/type/Str#method_Numeric»
229-
methods are used, or a L<RatStr> allomorph is created using L<val>,
230-
L<angle brackets|/language/quoting#index-entry-<_>_word_quote>, or other
231-
allomorph-producing means, such as arguments to
232-
L«C<MAIN> routine|/language/functions#sub_MAIN» or calling
233-
L«C<RatStr.new>|/type/RatStr#method_new». Mathematical operations are B<NOT>
234-
subject to this rule and instead degrade their result to a L<Num> instead.
213+
a result of some mathematical expression), however, a "fattish" L<Rat> with
214+
larger denominator will be created.
235215
236216
=head2 C<FatRat>
237217
@@ -307,19 +287,9 @@ which can be explosive.
307287
=head2 Zero-Denominator Rationals
308288
309289
A Zero-Denominator Rational is a numeric that does role L<Rational>, which
310-
among core numerics would be L<Rat>, L<MidRat>, and L<FatRat> objects, which
290+
among core numerics would be L<Rat> and L<FatRat> objects, which
311291
has denominator of zero.
312292
313-
On creation, the numerator of such numerics is always normalized to C<-1>,
314-
C<1>, C<0>, depending on whether the original numerator is negative,
315-
positive, or zero respectively:
316-
317-
=begin code
318-
say <1000/0>.nude; # OUTPUT: «(1 0)␤»
319-
say <-1000/0>.nude; # OUTPUT: «(-1 0)␤»
320-
say <0/0>.nude; # OUTPUT: «(0 0)␤»
321-
=end code
322-
323293
Operations that can be performed without requiring actual division to occur
324294
are non-explosive. For example, you can separately examine
325295
L<numerator> and L<denominator> in the L<nude> or perform mathematical
@@ -360,23 +330,20 @@ L<Str> types and will be accepted by any type constraint that requires an L<Int>
360330
361331
Allomorphs can be created using L«angle brackets|/language/quoting#Word_quoting:_<_>», either used
362332
standalone or as part of a hash key lookup; directly
363-
using method C<.new>; and are also provided by some constructs such as
364-
parameters of L«C<sub MAIN>|/language/functions#sub_MAIN» or, in the case of the L<MidRat>
365-
allomorph, L<Rational> literals with large denominators.
333+
using method C<.new> and are also provided by some constructs such as
334+
parameters of L«C<sub MAIN>|/language/functions#sub_MAIN».
366335
367336
=begin code
368-
say <42>.^name; # OUTPUT: «IntStr␤»
369-
say <42e0>.^name; # OUTPUT: «NumStr␤»
370-
say < 42+42i>.^name; # OUTPUT: «ComplexStr␤»
371-
say < 1/2>.^name; # OUTPUT: «RatStr␤»
372-
say <0.5>.^name; # OUTPUT: «RatStr␤»
373-
say <1/99999999999999999999>.^name; # OUTPUT: «MidRat␤»
374-
say < 1/99999999999999999999>.^name; # OUTPUT: «MidRatStr␤»
337+
say <42>.^name; # OUTPUT: «IntStr␤»
338+
say <42e0>.^name; # OUTPUT: «NumStr␤»
339+
say < 42+42i>.^name; # OUTPUT: «ComplexStr␤»
340+
say < 1/2>.^name; # OUTPUT: «RatStr␤»
341+
say <0.5>.^name; # OUTPUT: «RatStr␤»
375342
376343
@*ARGS = "42";
377-
sub MAIN($x) { say $x.^name } # OUTPUT: «IntStr␤»
344+
sub MAIN($x) { say $x.^name } # OUTPUT: «IntStr␤»
378345
379-
say IntStr.new(42, "42").^name; # OUTPUT: «IntStr␤»
346+
say IntStr.new(42, "42").^name; # OUTPUT: «IntStr␤»
380347
=end code
381348
382349
A couple of constructs above have a space after the opening angle bracket. That space isn't
@@ -405,8 +372,6 @@ The core language offers the following allomorphs:
405372
NumStr | Num and Str | <42e0>
406373
ComplexStr | Complex and Str | < 1+2i>
407374
RatStr | Rat and Str | <1.5>
408-
MidRat | Rat and FatRat | <1/99999999999999999999>
409-
MidRatStr | Rat, FatRat, and Str | < 1/99999999999999999999>
410375
411376
=end table
412377
@@ -447,7 +412,6 @@ my $al := IntStr.new: 42, "forty two";
447412
say $al.Str; # OUTPUT: «forty two␤»
448413
say +$al; # OUTPUT: «42␤»
449414
450-
say <1/99999999999999999999>.^name; # OUTPUT: «MidRat␤»
451415
say <1/99999999999999999999>.Rat.^name; # OUTPUT: «Rat␤»
452416
say <1/99999999999999999999>.FatRat.^name; # OUTPUT: «FatRat␤»
453417
=end code
@@ -740,42 +704,24 @@ result.
740704
741705
The infectiousness is as follows, with the most infectious type listed first:
742706
743-
=begin table
707+
=item * Complex
744708
745-
Type | Comments |
746-
========+=================================================+
747-
Complex | |
748-
Num | |
749-
FatRat | |
750-
MidRat | Special infectiousness. See prose that follows. |
751-
Rat | |
752-
Int | |
709+
=item * Num
753710
754-
=end table
711+
=item * FatRat
755712
756-
The L<MidRat> type is a special type that offers greater precision, like a L<FatRat> type, yet
757-
has the same infectiousness as a L<Rat> type. In other words, operations involving a L<MidRat>
758-
type and a L<MidRat>, L<Rat>, or L<Int> type would result in a L<Rat> result, B<not> L<MidRat>
759-
result (or a L<Num> result if after reduction the denominator ended up over 64-bits, too large for
760-
a L<Rat>). Otherwise, we're dealing with a type more infectious than a L<MidRat> and the result will
761-
be of that type.
713+
=item * Rat
762714
763-
Some examples of what we discussed:
715+
=item * Int
764716
765717
=begin code
766718
say (2 + 2e0).^name; # Int + Num => OUTPUT: «Num␤»
767719
say (½ + ½).^name; # Rat + Rat => OUTPUT: «Rat␤»
768720
say (FatRat.new(1,2) + ½).^name; # FatRat + Rat => OUTPUT: «FatRat␤»
769-
say (FatRat.new(1,2) + <1/99999999999999999999>).^name; # FatRat + MidRat => OUTPUT: «FatRat␤»
770-
771-
say (99999999999999999999 * <1/99999999999999999999>).^name;
772-
# Int * MidRat (after reduction, denominator fits into a Rat) => OUTPUT: «Rat␤»
773-
say (1 + <1/99999999999999999999>).^name;
774-
# Int * MidRat (after reduction, denominator too big to fit into a Rat) => OUTPUT: «Num␤»
775721
=end code
776722
777-
The allomorphs have the same infectiousness as their numeric component. Native types get autoboxed
778-
and have the same infectiousness as their boxed variant.
723+
The allomorphs have the same infectiousness as their numeric component. Native
724+
types get autoboxed and have the same infectiousness as their boxed variant.
779725
780726
=end pod
781727

0 commit comments

Comments
 (0)