Skip to content

Commit 717f9bd

Browse files
committed
Adds set algebra to the Math page
Which might or might not be what someone 1000 days ago had in mind, but it's at least what I would like to find if I go looking for math stuff in Perl 6. This refs #114, but still a lot TBD.
1 parent 29f856f commit 717f9bd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

doc/Language/math.pod6

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@ say "Identity with Ø ", so @id-empty.all; # OUTPUT: «Identity with Ø Tr
4646
4747
In this code, not only we check if the equalities in the algebra of sets hold, we also use, via L<sigilless variables|/language/variables#index-entry-\_(sigilless_variables)> and the Unicode form of the set operators, expressions that are as close as possible to the original form; C<A ∪ U === U>, for example, except for the use of the L<value identity operator <===>|/routine/===> is very close to the actual mathematical expression in the L<Wikipedia entry|https://en.wikipedia.org/wiki/Algebra_of_sets>.
4848
49+
We can even test de Morgan's law, as in the code below:
50+
51+
=begin code
52+
my @alphabet = 'a'..'z';
53+
my \U = @alphabet.Set;
54+
sub postfix:<⁻>(Set $a) { U ⊖ $a }
55+
my @sets;
56+
@sets.push: Set.new( @alphabet.pick( @alphabet.elems.rand)) for @alphabet;
57+
my ($de-Morgan1,$de-Morgan2) = (True,True);
58+
for @sets X @sets -> (\A, \B){
59+
$de-Morgan1 &&= (A ∪ B)⁻ === A⁻ ∩ B⁻;
60+
$de-Morgan2 &&= (A ∩ B)⁻ === A⁻ ∪ B⁻;
61+
}
62+
say "1st De Morgan is ", $de-Morgan1;
63+
say "2nd De Morgan is ", $de-Morgan2;
64+
=end code
65+
66+
We declare C<> as the I<complement> operation, which computes the symmetrical difference ⊖ between the Universal set C<U> and our set. Once that is declared, it is relatively easy to express operations such as the complementary of the union of A and B C<(A ∪ B)⁻>, with a notation that is very close to the original mathematical notation.
67+
4968
=head1 Arithmetic.
5069
5170
TBD

xt/words.pws

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,3 +1403,4 @@ xFB
14031403
xFC
14041404
xFD
14051405
dpkg
1406+
equalities

0 commit comments

Comments
 (0)