Skip to content

Commit 4b9d588

Browse files
committed
Adds section on sequences refs #114
1 parent f6577dd commit 4b9d588

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

doc/Language/math.pod6

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,35 @@ Some modules in the ecosystem can work with additional data types mathematically
8989
9090
=head1 Sequences
9191
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:
98+
99+
say 1,5,9 … * > 100;
100+
# OUTPUT: «(1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97 101)␤»
101+
say 1,3,9 … * > 337; # OUTPUT: «(1 3 9 27 81 243 729)␤»
102+
103+
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>:
106+
107+
say 1,1, * + * … * > 50;# OUTPUT: «(1 1 2 3 5 8 13 21 34 55)␤»
108+
109+
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 ℝ.
93121
94122
=head1 Mathematical constants
95123

0 commit comments

Comments
 (0)