You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/Language/math.pod6
+29-1Lines changed: 29 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -89,7 +89,35 @@ Some modules in the ecosystem can work with additional data types mathematically
89
89
90
90
=head1Sequences
91
91
92
-
TBD
92
+
A L<sequence|https://en.wikipedia.org/wiki/Sequence> is I<an enumerated collection of objects in which repetitions are allowed>, and also a first-class data type in Perl 6 called L<Seq>. C<Seq> is able to represent infinite sequences, like the natural numbers:
93
+
94
+
my \𝕟 = 1,2 … ∞;
95
+
say 𝕟[3];# OUTPUT: «4»
96
+
97
+
Infinite sequences use ∞, C<Inf> or C<*> (Whatever) as terminator. L<…> is the list generator, which in fact can understand arithmetic and geometric progression sequences as long as you insert the first numbers:
The first sequence will be terminated when the generated number is bigger than 100; the second sequence, which is a geometric progression, when it is bigger than 337.
104
+
105
+
The fact that an arbitrary generator can be used makes easy to generate sequences such as L<Fibonacci's|https://en.wikipedia.org/wiki/Fibonacci_number>:
We can, in fact, computeo the approximation to the L<golden ratio|https://en.wikipedia.org/wiki/Golden_ratio> this way:
110
+
111
+
my @phis = (2.FatRat, 1 + 1 / * ... *);
112
+
my @otherphi = (1 - @phis[200], 1 + 1 / * ... *);
113
+
say @otherphi[^10, |(20, 30 ... 100)];# OUTPUT: «((-0.61803398874989484820458683436563811772030918
114
+
-0.61803398874989484820458683436563811772030918
115
+
-0.61803398874989484820458683436563811772030918
116
+
-0.61803398874989484820458683436563811772030918
117
+
-0.61803398874989484820458683436563811772030918
118
+
-0.618033…»
119
+
120
+
The L<Math::Sequences|https://github.com/ajs/perl6-Math-Sequences> module includes many mathematical sequences, already defined for you. It defines many <sequences from the encyclopedia|https://oeis.org/>, some of them with their original name, such as ℤ or ℝ.
0 commit comments