line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2012-2015 Martin Becker. All rights reserved. |
2
|
|
|
|
|
|
|
# This package is free software; you can redistribute it and/or modify it |
3
|
|
|
|
|
|
|
# under the same terms as Perl itself. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: GF3.pm 60 2015-05-18 08:47:12Z demetri $ |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Math::ModInt::GF3; |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
88
|
use 5.006; |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
157
|
|
10
|
3
|
|
|
3
|
|
61
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
117
|
|
11
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
131
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ----- object definition ----- |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Math::ModInt::GF3=ARRAY(...) |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# .......... index .......... # .......... value .......... |
18
|
3
|
|
|
3
|
|
17
|
use constant F_RESIDUE => 0; # residue r, 0 .. 2 |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
206
|
|
19
|
3
|
|
|
3
|
|
16
|
use constant NFIELDS => 1; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
232
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# ----- class data ----- |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
BEGIN { |
24
|
3
|
|
|
3
|
|
16
|
require Math::ModInt; |
25
|
3
|
|
|
|
|
46
|
our @ISA = qw(Math::ModInt); |
26
|
3
|
|
|
|
|
2155
|
our $VERSION = '0.011'; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my @base = map { bless [$_] } 0..2; # singletons |
30
|
|
|
|
|
|
|
my @sgn = (0, 1, -1); |
31
|
|
|
|
|
|
|
my @neg = @base[0, 2, 1]; |
32
|
|
|
|
|
|
|
my @add = (\@base, [@base[1, 2, 0]], [@base[2, 0, 1]]); |
33
|
|
|
|
|
|
|
my @sub = (\@neg, [@base[1, 0, 2]], [@base[2, 1, 0]]); |
34
|
|
|
|
|
|
|
my @mul = ([@base[0, 0, 0]], \@base, \@neg ); |
35
|
|
|
|
|
|
|
my @pow = ( |
36
|
|
|
|
|
|
|
sub { $_[0] < 0? Math::ModInt->undefined: $base[!$_[0]] }, |
37
|
|
|
|
|
|
|
sub { $base[ 1] }, |
38
|
|
|
|
|
|
|
sub { $base[$_[0] % 2 + 1] }, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# ----- private methods ----- |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
3
|
|
534
|
sub _NEG { $neg[$_[0]->[F_RESIDUE]] } |
44
|
9
|
|
|
9
|
|
26
|
sub _ADD { $add[$_[0]->[F_RESIDUE]]->[$_[1]->[F_RESIDUE]] } |
45
|
9
|
|
|
9
|
|
20
|
sub _SUB { $sub[$_[0]->[F_RESIDUE]]->[$_[1]->[F_RESIDUE]] } |
46
|
9
|
|
|
9
|
|
25
|
sub _MUL { $mul[$_[0]->[F_RESIDUE]]->[$_[1]->[F_RESIDUE]] } |
47
|
18
|
|
|
18
|
|
34
|
sub _POW { $pow[$_[0]->[F_RESIDUE]]->($_[1]) } |
48
|
3
|
100
|
|
3
|
|
13
|
sub _INV { $_[0]->[F_RESIDUE]? $_[0]: Math::ModInt->undefined } |
49
|
25
|
|
|
25
|
|
80
|
sub _NEW { $base[$_[1] % 3] } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _DIV { |
52
|
9
|
|
|
9
|
|
11
|
my $this = $_[0]->[F_RESIDUE]; |
53
|
9
|
|
|
|
|
11
|
my $that = $_[1]->[F_RESIDUE]; |
54
|
9
|
100
|
|
|
|
23
|
return $that? $mul[$this]->[$that]: Math::ModInt->undefined; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
153
|
|
|
153
|
1
|
726
|
sub residue { $_[0]->[F_RESIDUE] } |
58
|
3
|
|
|
3
|
1
|
228
|
sub signed_residue { $sgn[$_[0]->[F_RESIDUE]] } |
59
|
234
|
|
|
234
|
1
|
686
|
sub modulus { 3 } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |