line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2009-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::GF2; |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
759
|
use 5.006; |
|
4
|
|
|
|
|
13
|
|
8
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
91
|
|
9
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
176
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ----- object definition ----- |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Math::ModInt::GF2=ARRAY(...) |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# .......... index .......... # .......... value .......... |
16
|
4
|
|
|
4
|
|
25
|
use constant F_RESIDUE => 0; # residue r, either 0 or 1 |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
239
|
|
17
|
4
|
|
|
4
|
|
21
|
use constant NFIELDS => 1; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
340
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ----- class data ----- |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
BEGIN { |
22
|
4
|
|
|
4
|
|
23
|
require Math::ModInt; |
23
|
4
|
|
|
|
|
65
|
our @ISA = qw(Math::ModInt); |
24
|
4
|
|
|
|
|
1995
|
our $VERSION = '0.012'; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my @base = map { bless [$_] } 0..1; # singletons |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# ----- private methods ----- |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
2
|
|
117
|
sub _NEG { $_[0] } |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _ADD { |
34
|
4
|
|
|
4
|
|
5
|
my ($this, $that) = @_; |
35
|
4
|
|
|
|
|
9
|
return $base[$this->[F_RESIDUE] ^ $that->[F_RESIDUE]]; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _SUB { |
39
|
4
|
|
|
4
|
|
4
|
my ($this, $that) = @_; |
40
|
4
|
|
|
|
|
9
|
return $base[$this->[F_RESIDUE] ^ $that->[F_RESIDUE]]; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _MUL { |
44
|
4
|
|
|
4
|
|
6
|
my ($this, $that) = @_; |
45
|
4
|
|
|
|
|
8
|
return $base[$this->[F_RESIDUE] & $that->[F_RESIDUE]]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _DIV { |
49
|
4
|
|
|
4
|
|
5
|
my ($this, $that) = @_; |
50
|
4
|
100
|
|
|
|
10
|
return $that->[F_RESIDUE]? $this: Math::ModInt->undefined; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _POW { |
54
|
8
|
|
|
8
|
|
19
|
my ($this, $exp) = @_; |
55
|
|
|
|
|
|
|
return |
56
|
8
|
100
|
100
|
|
|
28
|
$this->[F_RESIDUE] || $exp > 0? $this: |
|
|
100
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$exp? $this->undefined: $base[1]; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _INV { |
61
|
2
|
|
|
2
|
|
2
|
my ($this) = @_; |
62
|
2
|
100
|
|
|
|
6
|
return $this->[F_RESIDUE]? $this: Math::ModInt->undefined; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _NEW { |
66
|
16
|
|
|
16
|
|
24
|
my ($this, $int) = @_; |
67
|
16
|
|
|
|
|
44
|
return $base[$int & 1]; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _NEW2 { |
71
|
2
|
|
|
2
|
|
2
|
my ($this, $int) = @_; |
72
|
2
|
100
|
|
|
|
6
|
if ($int < 0) { |
73
|
|
|
|
|
|
|
# no arithmetic shift operation for negative perl integers, alas |
74
|
1
|
|
|
|
|
2
|
my $residue = $int & 1; |
75
|
1
|
|
|
|
|
5
|
return (($int - $residue) / 2, $base[$residue]); |
76
|
|
|
|
|
|
|
} |
77
|
1
|
|
|
|
|
3
|
return ($int >> 1, $base[$int & 1]); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub residue { |
81
|
73
|
|
|
73
|
1
|
216
|
my ($this) = @_; |
82
|
73
|
|
|
|
|
135
|
return $this->[F_RESIDUE]; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub signed_residue { |
86
|
2
|
|
|
2
|
1
|
55
|
my ($this) = @_; |
87
|
2
|
|
|
|
|
4
|
return - $this->[F_RESIDUE]; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub centered_residue { |
91
|
2
|
|
|
2
|
1
|
50
|
my ($this) = @_; |
92
|
2
|
|
|
|
|
4
|
return $this->[F_RESIDUE]; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub modulus { |
96
|
122
|
|
|
122
|
1
|
290
|
return 2; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |