line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2012-2019 Martin Becker, Blaubeuren. |
2
|
|
|
|
|
|
|
# This package is free software; you can distribute it and/or modify it |
3
|
|
|
|
|
|
|
# under the terms of the Artistic License 2.0 (see LICENSE file). |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Math::ModInt::GF3; |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
588
|
use 5.006; |
|
4
|
|
|
|
|
13
|
|
8
|
4
|
|
|
4
|
|
20
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
98
|
|
9
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
116
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ----- object definition ----- |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Math::ModInt::GF3=ARRAY(...) |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# .......... index .......... # .......... value .......... |
16
|
4
|
|
|
4
|
|
62
|
use constant F_RESIDUE => 0; # residue r, 0 .. 2 |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
261
|
|
17
|
4
|
|
|
4
|
|
25
|
use constant NFIELDS => 1; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
312
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ----- class data ----- |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
BEGIN { |
22
|
4
|
|
|
4
|
|
25
|
require Math::ModInt; |
23
|
4
|
|
|
|
|
83
|
our @ISA = qw(Math::ModInt); |
24
|
4
|
|
|
|
|
2092
|
our $VERSION = '0.012'; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my @base = map { bless [$_] } 0..2; # singletons |
28
|
|
|
|
|
|
|
my @sgn = (0, 1, -1); |
29
|
|
|
|
|
|
|
my @neg = @base[0, 2, 1]; |
30
|
|
|
|
|
|
|
my @add = (\@base, [@base[1, 2, 0]], [@base[2, 0, 1]]); |
31
|
|
|
|
|
|
|
my @sub = (\@neg, [@base[1, 0, 2]], [@base[2, 1, 0]]); |
32
|
|
|
|
|
|
|
my @mul = ([@base[0, 0, 0]], \@base, \@neg ); |
33
|
|
|
|
|
|
|
my @pow = ( |
34
|
|
|
|
|
|
|
sub { $_[0] < 0? Math::ModInt->undefined: $base[!$_[0]] }, |
35
|
|
|
|
|
|
|
sub { $base[ 1] }, |
36
|
|
|
|
|
|
|
sub { $base[$_[0] % 2 + 1] }, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
*centered_residue = \&signed_residue; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# ----- private methods ----- |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
3
|
|
157
|
sub _NEG { $neg[$_[0]->[F_RESIDUE]] } |
44
|
9
|
|
|
9
|
|
22
|
sub _ADD { $add[$_[0]->[F_RESIDUE]]->[$_[1]->[F_RESIDUE]] } |
45
|
9
|
|
|
9
|
|
22
|
sub _SUB { $sub[$_[0]->[F_RESIDUE]]->[$_[1]->[F_RESIDUE]] } |
46
|
9
|
|
|
9
|
|
20
|
sub _MUL { $mul[$_[0]->[F_RESIDUE]]->[$_[1]->[F_RESIDUE]] } |
47
|
18
|
|
|
18
|
|
30
|
sub _POW { $pow[$_[0]->[F_RESIDUE]]->($_[1]) } |
48
|
3
|
100
|
|
3
|
|
9
|
sub _INV { $_[0]->[F_RESIDUE]? $_[0]: Math::ModInt->undefined } |
49
|
25
|
|
|
25
|
|
60
|
sub _NEW { $base[$_[1] % 3] } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _DIV { |
52
|
9
|
|
|
9
|
|
13
|
my $this = $_[0]->[F_RESIDUE]; |
53
|
9
|
|
|
|
|
11
|
my $that = $_[1]->[F_RESIDUE]; |
54
|
9
|
100
|
|
|
|
21
|
return $that? $mul[$this]->[$that]: Math::ModInt->undefined; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
150
|
|
|
150
|
1
|
424
|
sub residue { $_[0]->[F_RESIDUE] } |
58
|
6
|
|
|
6
|
1
|
181
|
sub signed_residue { $sgn[$_[0]->[F_RESIDUE]] } |
59
|
231
|
|
|
231
|
1
|
538
|
sub modulus { 3 } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |