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