Planar.pm

filter: Statementstmt 62.5% 529 / 846 Branchbran 55.1% 181 / 328 Conditioncond 30.9% 26 / 84 MC/DCmcdc 25.4% 13 / 51 Subroutinesub 48.8% 65 / 133 Podpod 100% 79 / 79 totaltotal 58.7% 893 / 1521 CC 217 SCAR 28.4
CC
217
Cov
59%
verify_elements
132.0
from_lambda
66.9
_rotators
63.1
CRAP 17.1
↑ Summary Planar/Data.pm »
1 package Math::DifferenceSet::Planar;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Math::DifferenceSet::Planar::Data;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Math::Prime::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
8 is_prime is_power is_prime_power euler_phi factor_exp gcd
9 mulmod addmod invmod powmod divmod logint
10 6 );
11  
12 # Math::DifferenceSet::Planar=ARRAY(...)
13 # ............ index ............ # ........... value ...........
14 6 ▶use constant _F_ORDER => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use constant _F_BASE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use constant _F_EXPONENT => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶use constant _F_MODULUS => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶use constant _F_ZETA => 4; # "zeta" value
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶use constant _F_ETA => 5; # "eta" value, initially undef
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶use constant _F_THETA => 6; # translation amount from canonical set
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶use constant _F_PRINC_ELEMS => 7; # principal elements arrayref
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶use constant _F_SUPPL_ELEMS => 8; # supplemental elements arrayref
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ▶use constant _F_LAMBDA => 9; # plane logarithm value or undef
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 ▶use constant _F_ELEMENTS => 10; # elements arrayref, initially undef
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 ▶use constant _F_X_START => 11; # index of start element in elements
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶use constant _F_X_GAP => 12; # index of max gap element in elements
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶use constant _NFIELDS => 13;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 # usable native integer bits, typically 63 or 31
30 6 ▶use constant _NATIVE_BITS => logint(~0, 2);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 # max order safe to use with native integer arithmetic
32 6 ▶use constant _MAX_SMALL_ORDER => int( sqrt(2)*((1<<(_NATIVE_BITS>>1))-0.5) );
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 6 *canonize = \&lex_canonize;
35  
36 6 our $VERSION = '1.003';
37  
38 6 our $_MAX_ENUM_COUNT = 32768; # limit for stored rotator set size
39 6 our $_MAX_MEMO_COUNT = 4096; # limit for memoized values
40 6 our $_USE_SPACES_DB = 1; # enable looking up rotators
41  
42 6 my $current_data = undef; # current M::D::P::Data object
43  
44 6 my %memo_n_planes = (); # memoized n_planes values
45 6 my @memo_np_orders = (); # memoized orders FIFO
46 6 my %memo_rotators = (); # memoized rotators arrayrefs
47 6 my @memo_ro_orders = (); # memoized orders FIFO
48  
49 # ----- private subroutines -----
50  
51 # return complete rotator base if known or small enough, otherwise undef
52 #
53 # If structure is known:
54 #
55 # rotators -> +-----------+
56 # | radices ----------------------------> +-------+
57 # +-----------+ | r_1 |
58 # | depths -----------------> +-------+ +-------+
59 # +-----------+ | d_1 | | r_2 |
60 # | inverses -----> +-------+ +-------+ +-------+
61 # +-----------+ | i_1 | | d_2 | | ... |
62 # +-------+ +-------+ +-------+
63 # | i_2 | | ... | | r_n |
64 # +-------+ +-------+ +-------+
65 # | ... | | d_n |
66 # +-------+ +-------+
67 # | i_n |
68 # +-------+
69 #
70 # n
71 # ___ j
72 # R _ | | r k 0 < j < d
73 # j j ...j = | | k (mod M), = k k
74 # 1 2 n
75 # k = 1
76 #
77 # d - 1 _
78 # i r k = 1 (mod M), d > d > ... > d > 2
79 # k k 1 = 2 = = n =
80 #
81 #
82 # Otherwise, if number of rotators is small:
83 #
84 # rotators -> +-------+-------+-- --+-------+
85 # | R_1 | R_2 | ... | R_N |
86 # +-------+-------+-- --+-------+
87 #
88 # Otherwise, return undef.
89 #
90 10 ▶sub _rotators {
Subroutine _rotators: called CC=13 SCAR=41.4
91 10 my ($class, $order, $base, $exponent, $modulus) = @_;
92 10 ▶ return $memo_rotators{$order} if exists $memo_rotators{$order};
Branch: 1 branch
BranchTrueFalseTotal
if exists $memo_rotators{$order} 8 2 10
93 2 my $rotators = undef;
94 2 ▶ my $space = $_USE_SPACES_DB && $class->_data->get_space($order);
Condition33%1/3
$Math::DifferenceSet::Planar::_USE_SPACES_DB && $class->_data->get_space($order)
!ll&&!rl&&r
002
MC/DC0%0/2
$Math::DifferenceSet::Planar::_USE_SPACES_DB && $class->_data->get_space($order)
$Math::DifferenceSet::Planar::_USE_SPACES_DB $class->_data->get_space($order)
Truth table33%1/3
A && B
A= $Math::DifferenceSet::Planar::_USE_SPACES_DBB= $class->_data->get_space($order)
ABresult
0X0
100
111
95 2 ▶ if ($space) {
Branch: 2 branches
BranchTrueFalseTotal
if ($space) { } 2 0 2
elsif (_n_planes($order, $exponent, $modulus) <= $Math::DifferenceSet::Planar::_MAX_ENUM_COUNT) { } 0 0 0
96 2 my ($radices, $depths) = $space->rotator_space;
97 my $inverses = [
98 map {
99 3 invmod(
100 powmod($radices->[$_], $depths->[$_] - 1, $modulus),
101 $modulus
102 )
103 2 } 0 .. $#{$radices}
104 ];
105 2 $rotators = [$radices, $depths, $inverses];
106 }
107 elsif (_n_planes($order, $exponent, $modulus) <= $_MAX_ENUM_COUNT) {
108 0 my $mult = 3 * $exponent;
109 0 my $sieve = '1' x $modulus;
110 0 substr($sieve, 1, 1) = '0';
111 0 my $e = 1;
112 0 for (2 .. $mult) {
113 0 $e = mulmod($e, $base, $modulus);
114 0 substr($sieve, $e, 1) = '0';
115 }
116 0 my @rot = (1);
117 0 ▶ for (my $x = 2; $x < $modulus ; ++$x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $modulus) 0 0 0
118 0 ▶ if (substr $sieve, $x, 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr $sieve, $x, 1) 0 0 0
119 0 ▶ if (0 == $modulus % $x) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 == $modulus % $x) 0 0 0
120 0 ▶ for (my $i = $x; $i < $modulus; $i += $x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $modulus) 0 0 0
121 0 substr($sieve, $i, 1) = '0';
122 }
123 0 next;
124 }
125 0 substr($sieve, $x, 1) = '0';
126 0 my $e = $x;
127 0 for (2 .. $mult) {
128 0 $e = mulmod($e, $base, $modulus);
129 0 substr($sieve, $e, 1) = '0';
130 }
131 0 push @rot, $x;
132 0 ▶ last if $mult == @rot;
Branch: 1 branch
BranchTrueFalseTotal
if $mult == @rot 0 0 0
133 }
134 }
135 0 $rotators = \@rot;
136 }
137 2 $memo_rotators{$order} = $rotators;
138 2 push @memo_ro_orders, $order;
139 2 ▶ delete $memo_rotators{shift @memo_ro_orders}
Branch: 1 branch
BranchTrueFalseTotal
$Math::DifferenceSet::Planar::_MAX_MEMO_COUNT < @memo_ro_orders and do { delete $memo_rotators{shift @memo_ro_orders} } 0 2 2
140 while $_MAX_MEMO_COUNT < @memo_ro_orders;
141 2 return $rotators;
142 }
143  
144 # iterative rotator base generator, slow, but memory efficient
145 0 ▶sub _sequential_rotators {
Subroutine _sequential_rotators: not called CC=2 SCAR=17.9
146 0 my ($order, $base, $exponent, $modulus) = @_;
147 0 my $n_planes = _n_planes($order, $exponent, $modulus);
148 0 my $mult = 3 * $exponent;
149 0 my @pf = map { $_->[0] } factor_exp($modulus);
150 0 ▶ pop @pf if $pf[-1] == $modulus;
Branch: 1 branch
BranchTrueFalseTotal
if $pf[-1] == $modulus 0 0 0
151 0 my $mx = 0;
152 0 my $x = 0;
153 0 ▶ return sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
154 0 ▶ return 0 if $mx >= $n_planes;
Branch: 1 branch
BranchTrueFalseTotal
if $mx >= $n_planes 0 0 0
155 ELEMENT:
156 0 while (1) {
157 0 ++$x;
158 0 foreach my $p (@pf) {
159 0 ▶ next ELEMENT if !($x % $p);
Branch: 1 branch
BranchTrueFalseTotal
unless $x % $p 0 0 0
160 }
161 0 my $e = $x;
162 0 for (2 .. $mult) {
163 0 $e = mulmod($e, $base, $modulus);
164 0 ▶ next ELEMENT if $e < $x;
Branch: 1 branch
BranchTrueFalseTotal
if $e < $x 0 0 0
165 }
166 0 ++$mx;
167 0 return $x;
168 }
169 0 };
170 }
171  
172 # structured rotator base iterator, time and space efficient
173 10 ▶sub _structured_rotators {
Subroutine _structured_rotators: called CC=1 SCAR=0.0
174 10 my ($modulus, $rotators) = @_;
175 10 my ($radices, $depths, $inverses) = @{$rotators};
176 10 my @index = (0) x @{$radices};
177 10 my $next = 1;
178 17 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
179 17 ▶ return 0 if !$next;
Branch: 1 branch
BranchTrueFalseTotal
unless $next 0 17 17
180 17 my $element = $next;
181 17 my $i = 0;
182 17 ▶ while ($i < @index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @index) 17 7 24
183 17 ▶ if (++$index[$i] < $depths->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$index[$i] < $depths->[$i]) 10 7 17
184 10 $next = mulmod($next, $radices->[$i], $modulus);
185 10 return $element;
186 }
187 }
188 continue {
189 7 $index[$i] = 0;
190 7 $next = mulmod($next, $inverses->[$i], $modulus);
191 7 ++$i;
192 }
193 7 $next = 0;
194 7 return $element;
195 10 };
196 }
197  
198 # format a planar difference set space description, like '7^3 [2^6 5^2]'
199 0 ▶sub _space_description {
Subroutine _space_description: not called CC=1 SCAR=6.9
200 0 my ($spc) = @_;
201 0 my $order = $spc->order;
202 0 my $mul_radix = $spc->mul_radix;
203 0 my $mul_depth = $spc->mul_depth;
204 0 my ($radices, $depths) = $spc->rotator_space;
205 0 my @space = map {; "$radices->[$_]^$depths->[$_]"} 0 .. $#{$radices};
206 0 return "$order: $mul_radix^$mul_depth [@space]";
207 }
208  
209 # integer exponentiation
210 7 ▶sub _pow {
Subroutine _pow: called CC=7 SCAR=19.5
211 7 my ($base, $exponent) = @_;
212 7 ▶ return 0 if $base <= 0 || $exponent < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $base <= 0 or $exponent < 0 2 5 7
Condition100%3/3
$base <= 0 or $exponent < 0
l!l&&r!l&&!r
115
MC/DC100%2/2
$base <= 0 or $exponent < 0
$base <= 0 $exponent < 0
Truth table100%3/3
A or B
A= $base <= 0B= $exponent < 0
ABresult
1X1
011
000
213 5 ▶ return 0 if logint($base, 2) * $exponent >= _NATIVE_BITS;
Branch: 1 branch
BranchTrueFalseTotal
if &logint($base, 2) * $exponent >= 63 1 4 5
214 4 my $power = 1;
215 4 ▶ while ($exponent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exponent) 14 4 18
216 14 ▶ $power *= $base if 1 & $exponent;
Branch: 1 branch
BranchTrueFalseTotal
if 1 & $exponent 8 6 14
217 14 ▶ $exponent >>= 1 and $base *= $base;
Branch: 1 branch
BranchTrueFalseTotal
$exponent >>= 1 and $base *= $base 10 4 14
218 }
219 4 return $power;
220 }
221  
222 # check whether order is small enough and calculate modulus
223 35 ▶sub _modulus {
Subroutine _modulus: called CC=2 SCAR=6.9
224 35 my ($order) = @_;
225 35 ▶ if ($order > _MAX_SMALL_ORDER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($order > 3037000499) 1 34 35
226 1 croak "order $order too large for this platform\n";
227 }
228 34 return +($order + 1) * $order + 1;
229 }
230  
231 # calculate minimal equivalent of a factor
232 52 ▶sub _min_factor {
Subroutine _min_factor: called CC=3 SCAR=11.0
233 52 my ($factor, $base, $modulus) = @_;
234 52 my $f0 = $factor;
235 52 my $f = mulmod($f0, $base, $modulus);
236 52 ▶ while ($f != $f0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f != $f0) 242 52 294
237 242 ▶ $factor = $f if $f < $factor;
Branch: 1 branch
BranchTrueFalseTotal
if $f < $factor 11 231 242
238 242 $f = mulmod($f, $base, $modulus);
239 }
240 52 return $factor;
241 }
242  
243 # boolean whether an ordered strictly increasing list contains an element
244 0 ▶sub _ol_contains {
Subroutine _ol_contains: not called CC=4 SCAR=30.0
245 0 my ($haystack, $needle) = @_;
246 0 my $lx = 0;
247 0 my $hx = $#{$haystack};
248 0 ▶ while ($lx <= $hx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lx <= $hx) 0 0 0
249 0 my $x = ($lx + $hx) >> 1;
250 0 my $v = $haystack->[$x];
251 0 my $cmp = $needle <=> $v;
252 0 ▶ return !0 if !$cmp;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmp 0 0 0
253 0 ▶ if ($cmp < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp < 0) { } 0 0 0
254 0 $hx = $x - 1;
255 }
256 else {
257 0 $lx = $x + 1;
258 }
259 }
260 0 return !1;
261 }
262  
263 # calculate number of planes with memoization
264 0 ▶sub _n_planes {
Subroutine _n_planes: not called CC=3 SCAR=24.8
265 0 my ($order, $exponent, $modulus) = @_;
266 0 ▶ return $memo_n_planes{$order} if exists $memo_n_planes{$order};
Branch: 1 branch
BranchTrueFalseTotal
if exists $memo_n_planes{$order} 0 0 0
267 0 my $n_planes = $memo_n_planes{$order} =
268 euler_phi($modulus) / (3 *$exponent);
269 0 push @memo_np_orders, $order;
270 0 ▶ delete $memo_n_planes{shift @memo_np_orders}
Branch: 1 branch
BranchTrueFalseTotal
$Math::DifferenceSet::Planar::_MAX_MEMO_COUNT < @memo_np_orders and do { delete $memo_n_planes{shift @memo_np_orders} } 0 0 0
271 while $_MAX_MEMO_COUNT < @memo_np_orders;
272 0 return $n_planes;
273 }
274  
275 # arrange elements of a planar difference set in numerical order
276 # return arrayref of sorted list, start index, gap index
277 53 ▶sub _sort_elements {
Subroutine _sort_elements: called CC=6 SCAR=17.9
278 53 my $modulus = shift;
279 53 my @elements = sort { $a <=> $b } @_;
280 53 my $xs = my $xl = $#elements;
281 53 my $xg = my $xh = 0;
282 53 my $lo = $elements[$xl] - $modulus;
283 53 my $hi = $elements[0];
284 53 my $mg = my $ml = my $d = $hi - $lo;
285 53 ▶ while ($xh < $#elements) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xh < $#elements) 228 53 281
286 228 $xl = $xh++;
287 228 ($lo, $hi) = ($hi, $elements[$xh]);
288 228 $d = $hi - $lo;
289 228 ▶ $ml = $d, $xs = $xl if $d < $ml;
Branch: 1 branch
BranchTrueFalseTotal
if $d < $ml 80 148 228
290 228 ▶ $mg = $d, $xg = $xh if $d > $mg;
Branch: 1 branch
BranchTrueFalseTotal
if $d > $mg 38 190 228
291 }
292 53 ▶ croak "duplicate element: $elements[$xs]" if !$ml;
Branch: 1 branch
BranchTrueFalseTotal
unless $ml 2 51 53
293 51 ▶ croak 'delta 1 elements missing' if $ml > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $ml > 1 0 51 51
294 51 return (\@elements, $xs, $xg);
295 }
296  
297 # generate fill elements (0, 1 or 2 values)
298 37 ▶sub _fill_elements {
Subroutine _fill_elements: called CC=3 SCAR=11.0
299 37 my ($order, $modulus) = @_;
300 37 my $type = $order % 3;
301 37 ▶ return () if $type == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $type == 2 11 26 37
302 26 ▶ return (0) if $type == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $type == 0 5 21 26
303 21 my $m3 = $modulus / 3;
304 21 return ($m3, $m3 << 1);
305 }
306  
307 # recall elements or generate them, updating object attributes
308 205 ▶sub _elements {
Subroutine _elements: called CC=7 SCAR=19.5
309 205 my ($this) = @_;
310 205 my $elements = $this->[_F_ELEMENTS];
311 205 ▶ return $elements if $elements;
Branch: 1 branch
BranchTrueFalseTotal
if $elements 168 37 205
312 my ( $order, $base, $exponent, $modulus, $theta) =
313 37 @{$this}[_F_ORDER, _F_BASE, _F_EXPONENT, _F_MODULUS, _F_THETA];
314 37 my $mult = 3 * $exponent;
315 37 my @elem = ();
316 37 foreach my $e0 (@{$this->[_F_PRINC_ELEMS]}) {
317 15 my $e = $e0;
318 15 push @elem, addmod($e0, $theta, $modulus);
319 15 for (2 .. $mult) {
320 72 $e = mulmod($e, $base, $modulus);
321 72 push @elem, addmod($e, $theta, $modulus);
322 }
323 }
324 37 foreach my $e0 (@{$this->[_F_SUPPL_ELEMS]}) {
325 24 push @elem, addmod($e0, $theta, $modulus);
326 24 my $e = mulmod($e0, $base, $modulus);
327 24 ▶ while ($e != $e0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e != $e0) 48 24 72
328 48 push @elem, addmod($e, $theta, $modulus);
329 48 $e = mulmod($e, $base, $modulus);
330 }
331 }
332 37 foreach my $e0 (_fill_elements($order, $modulus)) {
333 47 push @elem, addmod($e0, $theta, $modulus);
334 }
335 37 ($elements) = @{$this}[_F_ELEMENTS, _F_X_START, _F_X_GAP] =
336 _sort_elements($modulus, @elem);
337 35 return $elements;
338 }
339  
340 # return data connection, creating it if not yet open
341 38 ▶sub _data {
Subroutine _data: called CC=2 SCAR=6.9
342 38 ▶ if (!defined $current_data) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $current_data) 5 33 38
343 5 $current_data = Math::DifferenceSet::Planar::Data->new;
344 }
345 38 return $current_data;
346 }
347  
348 # identify a plane by its rotator value with respect to a given plane
349 # (setting its lambda value if possible)
350 16 ▶sub _log {
Subroutine _log: called CC=12 SCAR=24.9
351 16 my ($this, $ref) = @_;
352 16 my $modulus = $this->[_F_MODULUS];
353 16 my $delta = -$this->[_F_THETA];
354 16 my $ref_lambda = $ref->[_F_LAMBDA];
355 16 my $factor = 0;
356 16 my %this_e = ();
357 16 my $this_elements = $this->_elements;
358 16 foreach my $e (@{$this_elements}) {
359 75 ▶ $this_e{$delta? addmod($e, $delta, $modulus): $e} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$delta ? : 49 26 75
360 }
361 16 ▶ if (@{$ref->[_F_PRINC_ELEMS]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$ref->[7];}) { } 7 9 16
362 7 my $inv_r = invmod($ref->[_F_PRINC_ELEMS]->[0], $modulus);
363 ELEM:
364 7 foreach my $o (@{$this->[_F_PRINC_ELEMS]}) {
365 7 my $ro = mulmod($inv_r, $o, $modulus);
366 7 foreach my $e (@{$ref->[_F_PRINC_ELEMS]}) {
367 7 ▶ next ELEM if !exists $this_e{ mulmod($e, $ro, $modulus) };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $this_e{&mulmod($e, $ro, $modulus)} 0 7 7
368 }
369 7 $factor = $ro;
370 7 last;
371 }
372 }
373 else {
374 9 my $ri = $this->iterate_rotators;
375 ROT:
376 9 ▶ while (my $ro = $ri->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ro = &$ri()) 16 0 16
377 16 foreach my $e (@{$ref->[_F_SUPPL_ELEMS]}) {
378 16 ▶ next ROT if !exists $this_e{ mulmod($e, $ro, $modulus) };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $this_e{&mulmod($e, $ro, $modulus)} 7 9 16
379 }
380 9 $factor = $ro;
381 9 last;
382 }
383 }
384 16 ▶ croak 'unaligned sets' if !$factor;
Branch: 1 branch
BranchTrueFalseTotal
unless $factor 0 16 16
385 16 my $base = $this->[_F_BASE];
386 16 ▶ if ($ref_lambda) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_lambda) 16 0 16
387 16 $this->[_F_LAMBDA] =
388 _min_factor(
389 mulmod($ref_lambda, $factor, $modulus), $base, $modulus
390 );
391 }
392 16 return $factor;
393 }
394  
395 # $factor = _find_factor($ds1, $ds2);
396 27 ▶sub _find_factor {
Subroutine _find_factor: called CC=6 SCAR=18.1
397 27 my ($this, $that) = @_;
398 27 ▶ return 1 if $this == $that;
Branch: 1 branch
BranchTrueFalseTotal
if $this == $that 1 26 27
399 26 my $order = $this->order;
400 26 ▶ croak 'sets of same size expected' if $order != $that->order;
Branch: 1 branch
BranchTrueFalseTotal
if $order != $that->order 2 24 26
401 24 my $log_this = $this->[_F_LAMBDA];
402 24 my $log_that = $that->[_F_LAMBDA];
403 24 ▶ if (!$log_that) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $log_that) { } 16 8 24
elsif (not $log_this) { } 0 8 8
404 16 $log_that = _log($that, $this);
405 }
406 elsif (!$log_this) {
407 0 $log_this = _log($this, $that);
408 }
409 24 ▶ return $log_this? divmod($log_that, $log_this, $this->modulus): $log_that;
Branch: 1 branch
BranchTrueFalseTotal
$log_this ? : 24 0 24
410 }
411  
412 # translation amount between a multiple of a set and another set
413 35 ▶sub _delta_f {
Subroutine _delta_f: called CC=1 SCAR=0.0
414 35 my ($this, $factor, $that) = @_;
415 35 my $modulus = $this->modulus;
416 35 my ($x) = $this->find_delta( invmod($factor, $modulus) );
417 35 my $elements = $that->_elements;
418 35 my $s = $elements->[$that->[_F_X_START]];
419 35 return addmod($s, -mulmod($x, $factor, $modulus), $modulus);
420 }
421  
422 # $bool = _is_mult($factor, $base, $mult, $modulus);
423 25 ▶sub _is_mult {
Subroutine _is_mult: called CC=4 SCAR=14.1
424 25 my ($factor, $base, $mult, $modulus) = @_;
425 25 ▶ return !0 if $factor == $base;
Branch: 1 branch
BranchTrueFalseTotal
if $factor == $base 0 25 25
426 25 my $p = $base;
427 25 for (2 .. $mult-1) {
428 130 $p = mulmod($p, $base, $modulus);
429 130 ▶ return !0 if $factor == $p;
Branch: 1 branch
BranchTrueFalseTotal
if $factor == $p 0 130 130
430 }
431 25 return !1;
432 }
433  
434 # ($order, $base, $exponent, $key) = _order_from_params(@_);
435 18 ▶sub _order_from_params {
Subroutine _order_from_params: called CC=7 SCAR=28.2
436 18 my ($order, $exponent) = @_;
437 18 my $base = undef;
438 18 ▶ if (defined $exponent) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $exponent) { } 0 18 18
439 0 $base = $order;
440 0 ▶ croak "order base $base is not a prime" if !is_prime($base);
Branch: 1 branch
BranchTrueFalseTotal
unless &is_prime($base) 0 0 0
441 0 $order = _pow($base, $exponent);
442 0 ▶ croak "order $base ** $exponent too large for this platform"
Branch: 1 branch
BranchTrueFalseTotal
if not $order or $order > 3037000499 0 0 0
Condition0%0/3
not $order or $order > 3037000499
l!l&&r!l&&!r
000
MC/DC0%0/2
not $order or $order > 3037000499
not $order $order > 3037000499
Truth table0%0/3
not(A) or B
A= not $orderB= $order > 3037000499
ABresult
1X1
011
000
443 if !$order || $order > _MAX_SMALL_ORDER;
444 }
445 else {
446 18 ▶ croak "order $order too large for this platform"
Branch: 1 branch
BranchTrueFalseTotal
if $order > 3037000499 0 18 18
447 if $order > _MAX_SMALL_ORDER;
448 18 $exponent = is_prime_power($order, \$base);
449 18 ▶ croak "order $order is not a prime power" if !$exponent;
Branch: 1 branch
BranchTrueFalseTotal
unless $exponent 0 18 18
450 }
451 18 return ($order, $base, $exponent);
452 }
453  
454 # ($this, $order, $base, $exponent, $modulus) = _full_params(@_);
455 12 ▶sub _full_params {
Subroutine _full_params: called CC=3 SCAR=11.8
456 12 my $this = shift;
457 12 my ($order, $base, $exponent, $modulus);
458 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 12 12
459 0 ($order, $base, $exponent) = _order_from_params(@_);
460 0 $modulus = _modulus($order);
461 }
462 else {
463 12 ▶ croak 'parameters expected if called as a class method' if !ref $this;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 12 12
464 ( $order, $base, $exponent, $modulus) =
465 12 @{$this}[_F_ORDER, _F_BASE, _F_EXPONENT, _F_MODULUS];
466 }
467 12 return ($this, $order, $base, $exponent, $modulus);
468 }
469  
470 # $bool = $class->_known_ref('ref_std', $base, $exponent);
471 0 ▶sub _known_ref {
Subroutine _known_ref: not called CC=7 SCAR=40.3
472 0 my ($class, $attribute, $base, $exponent) = @_;
473 0 ▶ my $order = defined($exponent)? _pow($base, $exponent): $base;
Branch: 1 branch
BranchTrueFalseTotal
defined $exponent ? : 0 0 0
474 0 ▶ return !1 if !$order || $order > $class->_data->max_order;
Branch: 1 branch
BranchTrueFalseTotal
if not $order or $order > $class->_data->max_order 0 0 0
Condition0%0/3
not $order or $order > $class->_data->max_order
l!l&&r!l&&!r
000
MC/DC0%0/2
not $order or $order > $class->_data->max_order
not $order $order > $class->_data->max_order
Truth table0%0/3
not(A) or B
A= not $orderB= $order > $class->_data->max_order
ABresult
1X1
011
000
475 0 my $pds = $class->_data->get($order, 'base', $attribute);
476 return
477 0 ▶ $pds && (!defined($exponent) || $base == $pds->base) &&
Condition0%0/9
$pds && (!defined($exponent) || $base == $pds->base) && $pds->$attribute != 0
!ll&&!rl&&r
000
$pds and !defined($exponent) || $base == $pds->base
!ll&&!rl&&r
000
not defined $exponent or $base == $pds->base
l!l&&r!l&&!r
000
MC/DC0%0/4
$pds && (!defined($exponent) || $base == $pds->base) && $pds->$attribute != 0
$pds not defined $exponent $base == $pds->base $pds->$attribute != 0
Truth table0%0/6
A and not(B) or C && D
A= $pdsB= not defined $exponentC= $base == $pds->baseD= $pds->$attribute != 0
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
478 $pds->$attribute != 0;
479 }
480  
481 # identity transformation
482 0 ▶sub _no_change { $_[0] }
Subroutine _no_change: not called CC=1 SCAR=6.9
483  
484 # $it = $class->_iterate_refs('ref_std', 'zeta_canonize', 10, 20);
485 0 ▶sub _iterate_refs {
Subroutine _iterate_refs: not called CC=1 SCAR=6.9
486 0 my ($class, $attribute, $transform, @minmax) = @_;
487 0 my $dit = $class->_data->iterate_refs($attribute, @minmax);
488 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
489 0 my $pds = $dit->();
490 0 ▶ return undef if !$pds;
Branch: 1 branch
BranchTrueFalseTotal
unless $pds 0 0 0
491 0 my $this = eval { $class->_from_pds($pds->order, $pds) };
492 0 ▶ return $this && $this->multiply($pds->$attribute)->$transform;
Condition0%0/3
$this && $this->multiply($pds->$attribute)->$transform
!ll&&!rl&&r
000
MC/DC0%0/2
$this && $this->multiply($pds->$attribute)->$transform
$this $this->multiply($pds->$attribute)->$transform
Truth table0%0/3
A && B
A= $thisB= $this->multiply($pds->$attribute)->$transform
ABresult
0X0
100
111
493 0 };
494 }
495  
496 # $ds = Math::DifferenceSet::Planar->_from_pds($order, $pds);
497 18 ▶sub _from_pds {
Subroutine _from_pds: called CC=6 SCAR=18.0
498 18 my ($class, $order, $pds) = @_;
499 18 my $modulus = _modulus($order);
500 18 my $base = $pds->base;
501 18 ▶ my $exponent = $base == $order? 1: logint($order, $base);
Branch: 1 branch
BranchTrueFalseTotal
$base == $order ? : 6 12 18
502 18 my $main = $pds->main_elements;
503 18 my (@princ, @suppl) = ();
504 18 foreach my $e (@{$main}) {
505 20 ▶ if (gcd($modulus, $e) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (&gcd($modulus, $e) == 1) { } 7 13 20
506 7 push @princ, $e;
507 }
508 else {
509 13 push @suppl, $e;
510 }
511 }
512 18 my $lambda = undef;
513 18 ▶ if (my $log = $pds->ref_std) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $log = $pds->ref_std) 18 0 18
514 18 ▶ $lambda =
Branch: 1 branch
BranchTrueFalseTotal
$log == 1 ? : 18 0 18
515 $log == 1? 1: _min_factor(invmod($log, $modulus), $base, $modulus);
516 }
517  
518 18 return bless [
519 $order,
520 $base,
521 $exponent,
522 $modulus,
523 0, # zeta
524 0, # eta
525 0, # theta
526 \@princ,
527 \@suppl,
528 $lambda,
529 undef, # elements
530 undef, # index_start
531 undef, # index_gap
532 ], $class;
533 }
534  
535 # ----- class methods -----
536  
537 0 ▶sub list_databases {
Subroutine list_databases: not called CC=1 SCAR=6.9
Pod documented
538 0 return Math::DifferenceSet::Planar::Data->list_databases;
539 }
540  
541 1 ▶sub set_database {
Subroutine set_database: called CC=1 SCAR=0.4
Pod documented
542 1 my $class = shift;
543 1 $current_data = Math::DifferenceSet::Planar::Data->new(@_);
544 0 return $class->available_count;
545 }
546  
547 # print "ok" if Math::DifferenceSet::Planar->available(9);
548 # print "ok" if Math::DifferenceSet::Planar->available(3, 2);
549 12 ▶sub available {
Subroutine available: called CC=6 SCAR=17.9
Pod documented
550 12 my ($class, $base, $exponent) = @_;
551 12 ▶ my $order = defined($exponent)? _pow($base, $exponent): $base;
Branch: 1 branch
BranchTrueFalseTotal
defined $exponent ? : 7 5 12
552 12 ▶ return !1 if !$order || $order > $class->_data->max_order;
Branch: 1 branch
BranchTrueFalseTotal
if not $order or $order > $class->_data->max_order 8 4 12
Condition100%3/3
not $order or $order > $class->_data->max_order
l!l&&r!l&&!r
354
MC/DC100%2/2
not $order or $order > $class->_data->max_order
not $order $order > $class->_data->max_order
Truth table100%3/3
not(A) or B
A= not $orderB= $order > $class->_data->max_order
ABresult
1X1
011
000
553 4 my $pds = $class->_data->get($order, 'base');
554 4 ▶ return !!$pds && (!defined($exponent) || $base == $pds->base);
Condition100%6/6
!!$pds && (!defined($exponent) || $base == $pds->base)
!ll&&!rl&&r
112
not defined $exponent or $base == $pds->base
l!l&&r!l&&!r
111
MC/DC100%3/3
!!$pds && (!defined($exponent) || $base == $pds->base)
!!$pds not defined $exponent $base == $pds->base
Truth table100%4/4
A && not(B) or C
A= !!$pdsB= not defined $exponentC= $base == $pds->base
ABCresult
0XX0
1000
11X1
1011
555 }
556  
557 # print "ok" if Math::DifferenceSet::Planar->known_space(9);
558 4 ▶sub known_space {
Subroutine known_space: called CC=4 SCAR=13.9
Pod documented
559 4 my ($class, $order) = @_;
560 4 ▶ return 0 if $order <= 0 || $order > $class->_data->sp_max_order;
Branch: 1 branch
BranchTrueFalseTotal
if $order <= 0 or $order > $class->_data->sp_max_order 2 2 4
Condition100%3/3
$order <= 0 or $order > $class->_data->sp_max_order
l!l&&r!l&&!r
112
MC/DC100%2/2
$order <= 0 or $order > $class->_data->sp_max_order
$order <= 0 $order > $class->_data->sp_max_order
Truth table100%3/3
A or B
A= $order <= 0B= $order > $class->_data->sp_max_order
ABresult
1X1
011
000
561 2 my $spc = $class->_data->get_space($order);
562 2 ▶ return 0 if !$spc;
Branch: 1 branch
BranchTrueFalseTotal
unless $spc 1 1 2
563 1 my ($rad) = $spc->rotator_space;
564 1 return 0 + @{$rad};
565 }
566  
567 # $desc = Math::DifferenceSet::Planar->known_space_desc(9);
568 0 ▶sub known_space_desc {
Subroutine known_space_desc: not called CC=4 SCAR=30.0
Pod documented
569 0 my ($class, $order) = @_;
570 0 ▶ return undef if $order <= 0 || $order > $class->_data->sp_max_order;
Branch: 1 branch
BranchTrueFalseTotal
if $order <= 0 or $order > $class->_data->sp_max_order 0 0 0
Condition0%0/3
$order <= 0 or $order > $class->_data->sp_max_order
l!l&&r!l&&!r
000
MC/DC0%0/2
$order <= 0 or $order > $class->_data->sp_max_order
$order <= 0 $order > $class->_data->sp_max_order
Truth table0%0/3
A or B
A= $order <= 0B= $order > $class->_data->sp_max_order
ABresult
1X1
011
000
571 0 my $spc = $class->_data->get_space($order);
572 0 ▶ return undef if !$spc;
Branch: 1 branch
BranchTrueFalseTotal
unless $spc 0 0 0
573 0 return _space_description($spc);
574 }
575  
576 # $ds = Math::DifferenceSet::Planar->new(9);
577 # $ds = Math::DifferenceSet::Planar->new(3, 2);
578 18 ▶sub new {
Subroutine new: called CC=2 SCAR=7.6
Pod documented
579 18 my $class = shift;
580 18 my ($order, $base, $exponent) = _order_from_params(@_);
581 18 my $pds = $class->_data->get($order);
582 18 ▶ if (!$pds) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pds) 0 18 18
583 0 my $key = join q[, ], @_;
584 0 croak "PDS($key) not available";
585 }
586 18 return $class->_from_pds($order, $pds);
587 }
588  
589 0 ▶sub lex_reference {
Subroutine lex_reference: not called CC=3 SCAR=24.8
Pod documented
590 0 my $class = shift;
591 0 my ($order, $base, $exponent) = _order_from_params(@_);
592 0 my $pds = $class->_data->get($order);
593 0 ▶ if ($pds && (my $lambda = $pds->ref_lex)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pds and my $lambda = $pds->ref_lex) 0 0 0
Condition0%0/3
$pds and my $lambda = $pds->ref_lex
!ll&&!rl&&r
000
MC/DC0%0/2
$pds and my $lambda = $pds->ref_lex
$pds my $lambda = $pds->ref_lex
Truth table0%0/3
A and B
A= $pdsB= my $lambda = $pds->ref_lex
ABresult
0X0
100
111
594 0 return $class->_from_pds($order, $pds)->multiply($lambda)->lex_canonize;
595 }
596 0 return undef;
597 }
598  
599 0 ▶sub gap_reference {
Subroutine gap_reference: not called CC=3 SCAR=24.8
Pod documented
600 0 my $class = shift;
601 0 my ($order, $base, $exponent) = _order_from_params(@_);
602 0 my $pds = $class->_data->get($order);
603 0 ▶ if ($pds && (my $lambda = $pds->ref_gap)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pds and my $lambda = $pds->ref_gap) 0 0 0
Condition0%0/3
$pds and my $lambda = $pds->ref_gap
!ll&&!rl&&r
000
MC/DC0%0/2
$pds and my $lambda = $pds->ref_gap
$pds my $lambda = $pds->ref_gap
Truth table0%0/3
A and B
A= $pdsB= my $lambda = $pds->ref_gap
ABresult
0X0
100
111
604 return
605 0 $class->_from_pds($order, $pds)->multiply($lambda)->gap_canonize;
606 }
607 0 return undef;
608 }
609  
610 0 ▶sub std_reference {
Subroutine std_reference: not called CC=3 SCAR=24.8
Pod documented
611 0 my $class = shift;
612 0 my ($order, $base, $exponent) = _order_from_params(@_);
613 0 my $pds = $class->_data->get($order);
614 0 ▶ if ($pds && (my $lambda = $pds->ref_std)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pds and my $lambda = $pds->ref_std) 0 0 0
Condition0%0/3
$pds and my $lambda = $pds->ref_std
!ll&&!rl&&r
000
MC/DC0%0/2
$pds and my $lambda = $pds->ref_std
$pds my $lambda = $pds->ref_std
Truth table0%0/3
A and B
A= $pdsB= my $lambda = $pds->ref_std
ABresult
0X0
100
111
615 return
616 0 $class->_from_pds($order, $pds)->zeta_canonize->multiply($lambda);
617 }
618 0 return undef;
619 }
620  
621 # $ds = Math::DifferenceSet::Planar->from_elements_fast(
622 # 0, 1, 3, 9, 27, 49, 56, 61, 77, 81
623 # );
624 16 ▶sub from_elements_fast {
Subroutine from_elements_fast: called CC=22 SCAR=31.5
Pod documented
625 16 my $class = shift;
626 16 my $order = $#_;
627 16 my ($base, $exponent);
628 16 ▶ $exponent = is_prime_power($order, \$base)
Branch: 1 branch
BranchTrueFalseTotal
$exponent = &is_prime_power($order, \$base) or croak("this implementation cannot handle order $order") 16 0 16
629 or croak "this implementation cannot handle order $order";
630 16 my $modulus = _modulus($order);
631 16 ▶ if (grep { $_ < 0 || $modulus <= $_ } @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ < 0 or $modulus <= $_;} @_) 0 16 16
Condition33%1/3
$_ < 0 || $modulus <= $_
l!l&&r!l&&!r
0075
MC/DC0%0/2
$_ < 0 || $modulus <= $_
$_ < 0 $modulus <= $_
Truth table33%1/3
A || B
A= $_ < 0B= $modulus <= $_
ABresult
1X1
011
000
632 0 my $max = $modulus - 1;
633 0 croak "element values inside range 0..$max expected";
634 }
635 16 my ($elements, $index_start, $index_gap) = _sort_elements($modulus, @_);
636 16 my $n_mult = 3 * $exponent;
637  
638 # find zeta and theta
639 16 my ($lx, $ux, $c) = (0, 0, 0);
640 16 my ($e0, $e2, $e3) = @{$elements}[$index_start, 0, 0];
641 16 my $is_m3 = $order % 3 == 1;
642 16 ▶ my $de = $is_m3? $modulus/3: $order + 1;
Branch: 1 branch
BranchTrueFalseTotal
$is_m3 ? : 9 7 16
643 16 my $bogus = 0;
644 16 ▶ while ($c != $de) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c != $de) 102 16 118
645 102 ▶ if ($c < $de) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c < $de) { } 65 37 102
646 65 ▶ $ux = 0 if ++$ux > $order;
Branch: 1 branch
BranchTrueFalseTotal
if ++$ux > $order 9 56 65
647 65 $e3 = $elements->[$ux];
648 65 ▶ $bogus = 1, last if $ux == $lx;
Branch: 1 branch
BranchTrueFalseTotal
if $ux == $lx 0 65 65
649 }
650 else {
651 37 ▶ $bogus = 1, last if ++$lx > $order;
Branch: 1 branch
BranchTrueFalseTotal
if ++$lx > $order 0 37 37
652 37 $e2 = $elements->[$lx];
653 }
654 102 ▶ $c = $e3 < $e2? $modulus + $e3 - $e2: $e3 - $e2;
Branch: 1 branch
BranchTrueFalseTotal
$e3 < $e2 ? : 14 88 102
655 }
656 16 ▶ croak "delta $de elements missing\n" if $bogus;
Branch: 1 branch
BranchTrueFalseTotal
if $bogus 0 16 16
657 16 my ($zeta, $theta);
658 16 ▶ if ($is_m3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_m3) { } 9 7 16
659 9 $theta = addmod($e3, $de, $modulus);
660 9 $zeta = mulmod($theta, $order - 1, $modulus);
661 }
662 else {
663 7 $zeta = addmod(mulmod($e3, $order, $modulus), -$e0, $modulus);
664 7 ▶ $theta = $zeta && divmod($zeta, $order - 1, $modulus);
Condition66%2/3
$zeta && &divmod($zeta, $order - 1, $modulus)
!ll&&!rl&&r
304
MC/DC50%1/2
$zeta && &divmod($zeta, $order - 1, $modulus)
$zeta &divmod($zeta, $order - 1, $modulus)
Truth table66%2/3
A && B
A= $zetaB= &divmod($zeta, $order - 1, $modulus)
ABresult
0X0
100
111
665 }
666  
667 my @elems =
668 16 sort { $a <=> $b } map { addmod($_, -$theta, $modulus) } @{$elements};
669 16 my @princ = ();
670 16 my @suppl = ();
671 16 my %todo = map {($_ => 1)} @elems;
672 16 foreach my $start (@elems) {
673 75 ▶ next if !exists $todo{$start};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $todo{$start} 47 28 75
674 28 delete $todo{$start};
675 28 my $this = mulmod($start, $base, $modulus);
676 28 my $count = 1;
677 28 ▶ while ($this != $start) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this != $start) 47 28 75
678 47 ▶ if (!defined delete $todo{$this}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined delete $todo{$this}) 0 47 47
679 0 croak
680 "bogus set: prime divisor $base of order $order " .
681 'is not a multiplier';
682 }
683 47 ++$count;
684 47 $this = mulmod($this, $base, $modulus);
685 }
686 28 ▶ if ($count == $n_mult) {
Branch: 2 branches
BranchTrueFalseTotal
if ($count == $n_mult) { } 7 21 28
elsif ($count >= 3) { } 9 12 21
687 7 ▶ if (gcd($start, $modulus) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (&gcd($start, $modulus) == 1) { } 7 0 7
688 7 push @princ, $start;
689 }
690 else {
691 0 push @suppl, $start;
692 }
693 }
694 elsif ($count >= 3) {
695 9 push @suppl, $start;
696 }
697 }
698 16 ▶ my $eta = $exponent == 1? $zeta: undef;
Branch: 1 branch
BranchTrueFalseTotal
$exponent == 1 ? : 6 10 16
699  
700 16 return bless [
701 $order,
702 $base,
703 $exponent,
704 $modulus,
705 $zeta,
706 $eta,
707 $theta,
708 \@princ,
709 \@suppl,
710 undef, # lambda
711 $elements,
712 $index_start,
713 $index_gap,
714 ], $class;
715 }
716  
717 # $ds = Math::DifferenceSet::Planar->from_elements(
718 # 0, 1, 3, 9, 27, 49, 56, 61, 77, 81
719 # );
720 16 ▶sub from_elements {
Subroutine from_elements: called CC=3 SCAR=11.1
Pod documented
721 16 my $class = shift;
722 16 my $this = $class->from_elements_fast(@_);
723 16 ▶ if(my $ref = eval { $class->new(@_ - 1) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = eval { do { $class->new(@_ - 1) } }) 16 0 16
724 16 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { () = $ref->find_linear_map($this); not $ref->multiply($factor)->translate($delta)->compare($this) } } or croak("apparently not a planar difference set") 16 0 16
725 16 my ($factor, $delta) = $ref->find_linear_map($this);
726 16 !$ref->multiply($factor)->translate($delta)->compare($this)
727 } or
728 croak 'apparently not a planar difference set';
729 }
730 16 return $this;
731 }
732  
733 # $ds = Math::DifferenceSet::Planar->from_lambda($order, $lambda);
734 # $ds = Math::DifferenceSet::Planar->from_lambda($order, $lambda, $theta);
735 1 ▶sub from_lambda {
Subroutine from_lambda: called CC=10 SCAR=42.0
Pod documented
736 1 my ($class, $order, $lambda, $theta) = @_;
737 1 my ($base, $exponent);
738 1 $exponent = is_prime_power($order, \$base);
739 1 ▶ croak "this implementation cannot handle order $order" if !$exponent;
Branch: 1 branch
BranchTrueFalseTotal
unless $exponent 0 1 1
740 1 my $modulus = _modulus($order);
741 0 ▶ croak "impossible lambda value $lambda" if gcd($modulus, $lambda) != 1;
Branch: 1 branch
BranchTrueFalseTotal
if &gcd($modulus, $lambda) != 1 0 0 0
742 0 my $l = mulmod($lambda, $base, $modulus);
743 0 ▶ while ($l != $lambda) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l != $lambda) 0 0 0
744 0 ▶ croak "non-canonical lambda value $lambda" if $l < $lambda;
Branch: 1 branch
BranchTrueFalseTotal
if $l < $lambda 0 0 0
745 0 $l = mulmod($l, $base, $modulus);
746 }
747 0 ▶ croak "non-canonical theta value $theta"
Branch: 1 branch
BranchTrueFalseTotal
if $theta and $theta < 0 || $modulus <= $theta 0 0 0
Condition0%0/6
$theta and $theta < 0 || $modulus <= $theta
!ll&&!rl&&r
000
$theta < 0 or $modulus <= $theta
l!l&&r!l&&!r
000
MC/DC0%0/3
$theta and $theta < 0 || $modulus <= $theta
$theta $theta < 0 $modulus <= $theta
Truth table0%0/4
A and B or C
A= $thetaB= $theta < 0C= $modulus <= $theta
ABCresult
0XX0
1000
11X1
1011
748 if $theta && ($theta < 0 || $modulus <= $theta);
749 0 my $ref = $class->std_reference($order);
750 0 ▶ croak "reference set of order $order not available" if !$ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 0 0 0
751 0 my $this = $ref->multiply($lambda);
752 0 ▶ return $theta? $this->translate($theta): $this;
Branch: 1 branch
BranchTrueFalseTotal
$theta ? : 0 0 0
753 }
754  
755 # $bool = Math::DifferenceSet::Planar->verify_elements(
756 # 0, 1, 3, 9, 27, 49, 56, 61, 77, 81
757 # );
758 0 ▶sub verify_elements {
Subroutine verify_elements: not called CC=11 SCAR=48.8
Pod documented
759 0 my ($class, @elements) = @_;
760 0 my $order = $#elements;
761 0 ▶ return undef if $order <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $order <= 1 0 0 0
762 0 my $modulus = _modulus($order);
763 0 my $median = ($modulus - 1) / 2;
764 0 my $seen = '0' x $median;
765 0 foreach my $r1 (@elements) {
766 0 ▶ return undef if $r1 < 0 || $modulus <= $r1 || $r1 != int $r1;
Branch: 1 branch
BranchTrueFalseTotal
if $r1 < 0 or $modulus <= $r1 or $r1 != int $r1 0 0 0
Condition0%0/6
$r1 < 0 or $modulus <= $r1 or $r1 != int $r1
l!l&&r!l&&!r
000
$r1 < 0 or $modulus <= $r1
l!l&&r!l&&!r
000
MC/DC0%0/3
$r1 < 0 or $modulus <= $r1 or $r1 != int $r1
$r1 < 0 $modulus <= $r1 $r1 != int $r1
Truth table0%0/4
A or B or C
A= $r1 < 0B= $modulus <= $r1C= $r1 != int $r1
ABCresult
1XX1
01X1
0011
0000
767 0 foreach my $r2 (@elements) {
768 0 ▶ last if $r1 == $r2;
Branch: 1 branch
BranchTrueFalseTotal
if $r1 == $r2 0 0 0
769 0 ▶ my $d = $r1 < $r2? $r2 - $r1: $modulus + $r2 - $r1;
Branch: 1 branch
BranchTrueFalseTotal
$r1 < $r2 ? : 0 0 0
770 0 ▶ $d = $modulus - $d if $d > $median;
Branch: 1 branch
BranchTrueFalseTotal
if $d > $median 0 0 0
771 0 ▶ return !1 if substr($seen, $d-1, 1)++;
Branch: 1 branch
BranchTrueFalseTotal
if substr($seen, $d - 1, 1)++ 0 0 0
772 }
773 }
774 0 return $median == $seen =~ tr/1//;
775 }
776  
777 # $it1 = Math::DifferenceSet::Planar->iterate_available_sets;
778 # $it2 = Math::DifferenceSet::Planar->iterate_available_sets(10, 20);
779 # while (my $ds = $it2->()) {
780 # ...
781 # }
782 0 ▶sub iterate_available_sets {
Subroutine iterate_available_sets: not called CC=1 SCAR=6.9
Pod documented
783 0 my ($class, @minmax) = @_;
784 0 my $dit = $class->_data->iterate(@minmax);
785 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
786 0 my $pds = $dit->();
787 0 ▶ return undef if !$pds;
Branch: 1 branch
BranchTrueFalseTotal
unless $pds 0 0 0
788 0 my $this = $class->_from_pds($pds->order, $pds);
789 0 return $this;
790 0 };
791 }
792  
793 0 ▶sub available_min_order { $_[0]->_data->min_order }
Subroutine available_min_order: not called CC=1 SCAR=6.9
Pod documented
794 0 ▶sub available_max_order { $_[0]->_data->max_order }
Subroutine available_max_order: not called CC=1 SCAR=6.9
Pod documented
795 0 ▶sub available_count { $_[0]->_data->count }
Subroutine available_count: not called CC=1 SCAR=6.9
Pod documented
796  
797 0 ▶sub known_std_ref {
Subroutine known_std_ref: not called CC=1 SCAR=6.9
Pod documented
798 0 my $class = shift;
799 0 return $class->_known_ref('ref_std', @_);
800 }
801  
802 0 ▶sub known_lex_ref {
Subroutine known_lex_ref: not called CC=1 SCAR=6.9
Pod documented
803 0 my $class = shift;
804 0 return $class->_known_ref('ref_lex', @_);
805 }
806  
807 0 ▶sub known_gap_ref {
Subroutine known_gap_ref: not called CC=1 SCAR=6.9
Pod documented
808 0 my $class = shift;
809 0 return $class->_known_ref('ref_gap', @_);
810 }
811  
812 0 ▶sub iterate_known_std_refs {
Subroutine iterate_known_std_refs: not called CC=1 SCAR=6.9
Pod documented
813 0 my ($class, @minmax) = @_;
814 0 return $class->_iterate_refs('ref_std', '_no_change', @minmax);
815 }
816  
817 0 ▶sub iterate_known_lex_refs {
Subroutine iterate_known_lex_refs: not called CC=1 SCAR=6.9
Pod documented
818 0 my ($class, @minmax) = @_;
819 0 return $class->_iterate_refs('ref_lex', 'lex_canonize', @minmax);
820 }
821  
822 0 ▶sub iterate_known_gap_refs {
Subroutine iterate_known_gap_refs: not called CC=1 SCAR=6.9
Pod documented
823 0 my ($class, @minmax) = @_;
824 0 return $class->_iterate_refs('ref_gap', 'gap_canonize', @minmax);
825 }
826  
827 0 ▶sub known_std_ref_min_order { $_[0]->_data->ref_min_order('ref_std') }
Subroutine known_std_ref_min_order: not called CC=1 SCAR=6.9
Pod documented
828 0 ▶sub known_std_ref_max_order { $_[0]->_data->ref_max_order('ref_std') }
Subroutine known_std_ref_max_order: not called CC=1 SCAR=6.9
Pod documented
829 0 ▶sub known_std_ref_count { $_[0]->_data->ref_count( 'ref_std') }
Subroutine known_std_ref_count: not called CC=1 SCAR=6.9
Pod documented
830 0 ▶sub known_lex_ref_min_order { $_[0]->_data->ref_min_order('ref_lex') }
Subroutine known_lex_ref_min_order: not called CC=1 SCAR=6.9
Pod documented
831 0 ▶sub known_lex_ref_max_order { $_[0]->_data->ref_max_order('ref_lex') }
Subroutine known_lex_ref_max_order: not called CC=1 SCAR=6.9
Pod documented
832 0 ▶sub known_lex_ref_count { $_[0]->_data->ref_count( 'ref_lex') }
Subroutine known_lex_ref_count: not called CC=1 SCAR=6.9
Pod documented
833 0 ▶sub known_gap_ref_min_order { $_[0]->_data->ref_min_order('ref_gap') }
Subroutine known_gap_ref_min_order: not called CC=1 SCAR=6.9
Pod documented
834 0 ▶sub known_gap_ref_max_order { $_[0]->_data->ref_max_order('ref_gap') }
Subroutine known_gap_ref_max_order: not called CC=1 SCAR=6.9
Pod documented
835 0 ▶sub known_gap_ref_count { $_[0]->_data->ref_count( 'ref_gap') }
Subroutine known_gap_ref_count: not called CC=1 SCAR=6.9
Pod documented
836  
837 # $min = Math::DifferenceSet::Planar->known_space_min_order;
838 0 ▶sub known_space_min_order { $_[0]->_data->sp_min_order }
Subroutine known_space_min_order: not called CC=1 SCAR=6.9
Pod documented
839  
840 # $max = Math::DifferenceSet::Planar->known_space_max_order;
841 0 ▶sub known_space_max_order { $_[0]->_data->sp_max_order }
Subroutine known_space_max_order: not called CC=1 SCAR=6.9
Pod documented
842  
843 # $count = Math::DifferenceSet::Planar->known_space_count;
844 0 ▶sub known_space_count { $_[0]->_data->sp_count }
Subroutine known_space_count: not called CC=1 SCAR=6.9
Pod documented
845  
846 # $it3 = Math::DifferenceSet::Planar->iterate_known_spaces;
847 # $it3 = Math::DifferenceSet::Planar->iterate_known_spaces(10,20);
848 # while (my $spc = $it3->()) {
849 # print "$spc\n";
850 # }
851 0 ▶sub iterate_known_spaces {
Subroutine iterate_known_spaces: not called CC=1 SCAR=6.9
Pod documented
852 0 my ($class, @minmax) = @_;
853 0 my $dit = $class->_data->iterate_spaces(@minmax);
854 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
855 0 my $spc = $dit->();
856 0 ▶ return undef if !$spc;
Branch: 1 branch
BranchTrueFalseTotal
unless $spc 0 0 0
857 0 return _space_description($spc);
858 0 };
859 }
860  
861 # ----- object methods -----
862  
863 # $o = $ds->order;
864 # $p = $ds->order_base;
865 # $n = $ds->order_exponent;
866 # $m = $ds->modulus;
867 # $z = $ds->zeta;
868 # $t = $ds->theta;
869 # $l = $ds->lambda;
870 274 ▶sub order { $_[0]->[_F_ORDER ] }
Subroutine order: called CC=1 SCAR=0.0
Pod documented
871 0 ▶sub order_base { $_[0]->[_F_BASE ] }
Subroutine order_base: not called CC=1 SCAR=6.9
Pod documented
872 0 ▶sub order_exponent { $_[0]->[_F_EXPONENT] }
Subroutine order_exponent: not called CC=1 SCAR=6.9
Pod documented
873 103 ▶sub modulus { $_[0]->[_F_MODULUS ] }
Subroutine modulus: called CC=1 SCAR=0.0
Pod documented
874 1 ▶sub zeta { $_[0]->[_F_ZETA ] }
Subroutine zeta: called CC=1 SCAR=0.0
Pod documented
875 1 ▶sub theta { $_[0]->[_F_THETA ] }
Subroutine theta: called CC=1 SCAR=0.0
Pod documented
876 0 ▶sub lambda { $_[0]->[_F_LAMBDA ] }
Subroutine lambda: not called CC=1 SCAR=6.9
Pod documented
877  
878 0 ▶sub min_element {
Subroutine min_element: not called CC=1 SCAR=6.9
Pod documented
879 0 my ($this) = @_;
880 0 my $elements = $this->_elements;
881 0 return $elements->[0];
882 }
883  
884 0 ▶sub max_element {
Subroutine max_element: not called CC=1 SCAR=6.9
Pod documented
885 0 my ($this) = @_;
886 0 my $elements = $this->_elements;
887 0 return $elements->[-1];
888 }
889  
890 0 ▶sub n_planes {
Subroutine n_planes: not called CC=1 SCAR=6.9
Pod documented
891 0 my ($this, $order, $base, $exponent, $modulus) = _full_params(@_);
892 0 return _n_planes($order, $exponent, $modulus)
893 }
894  
895 # @e = $ds->elements;
896 1 ▶sub elements {
Subroutine elements: called CC=2 SCAR=14.0
Pod documented
897 1 my ($this) = @_;
898 1 my $elements = $this->_elements;
899 0 ▶ return 0+@{$elements} if !wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
900 0 my $x_start = $this->[_F_X_START];
901 0 return @{$elements}[$x_start .. $#{$elements}, 0 .. $x_start-1];
902 }
903  
904 # $e0 = $ds->element(0);
905 0 ▶sub element {
Subroutine element: not called CC=4 SCAR=30.0
Pod documented
906 0 my ($this, $index) = @_;
907 0 my $n_elems = $this->[_F_ORDER] + 1;
908 0 ▶ return undef if $index < -$n_elems || $n_elems <= $index;
Branch: 1 branch
BranchTrueFalseTotal
if $index < -$n_elems or $n_elems <= $index 0 0 0
Condition0%0/3
$index < -$n_elems or $n_elems <= $index
l!l&&r!l&&!r
000
MC/DC0%0/2
$index < -$n_elems or $n_elems <= $index
$index < -$n_elems $n_elems <= $index
Truth table0%0/3
A or B
A= $index < -$n_elemsB= $n_elems <= $index
ABresult
1X1
011
000
909 0 my $elements = $this->_elements;
910 0 my $x_eff = $this->[_F_X_START] + $index;
911 0 ▶ $x_eff -= $n_elems if $x_eff >= $n_elems;
Branch: 1 branch
BranchTrueFalseTotal
if $x_eff >= $n_elems 0 0 0
912 0 return $elements->[$x_eff];
913 }
914  
915 # @e = $ds->elements_sorted;
916 0 ▶sub elements_sorted {
Subroutine elements_sorted: not called CC=1 SCAR=6.9
Pod documented
917 0 my ($this) = @_;
918 0 my $elements = $this->_elements;
919 0 return @{$elements};
920 }
921  
922 # $e0 = $ds->element_sorted(0);
923 0 ▶sub element_sorted {
Subroutine element_sorted: not called CC=1 SCAR=6.9
Pod documented
924 0 my ($this, $index) = @_;
925 0 my $elements = $this->_elements;
926 0 return $elements->[$index];
927 }
928  
929 # $ds1 = $ds->translate(1);
930 39 ▶sub translate {
Subroutine translate: called CC=6 SCAR=17.9
Pod documented
931 39 my ($this, $delta) = @_;
932 39 my $modulus = $this->[_F_MODULUS];
933 39 $delta %= $modulus;
934 39 ▶ return $this if !$delta;
Branch: 1 branch
BranchTrueFalseTotal
unless $delta 8 31 39
935 31 my $that = bless [@{$this}], ref $this;
936 31 my $elements = $this->[_F_ELEMENTS];
937 31 ▶ if ($elements) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elements) 20 11 31
938 20 my $lim = $modulus - $delta;
939 20 my @elems = my @wrap = ();
940 20 foreach my $e (@{$elements}) {
941 145 ▶ if ($e < $lim) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e < $lim) { } 81 64 145
942 81 push @wrap, $e + $delta;
943 }
944 else {
945 64 push @elems, $e - $lim;
946 }
947 }
948 20 my $dx = @elems;
949 20 push @elems, @wrap;
950 20 my $x_start = addmod($this->[_F_X_START], $dx, 0+@elems);
951 20 my $x_gap = addmod($this->[_F_X_GAP], $dx, 0+@elems);
952 20 $that->[_F_ELEMENTS] = \@elems;
953 20 $that->[_F_X_START] = $x_start;
954 20 $that->[_F_X_GAP] = $x_gap;
955 }
956 31 my ($order, $zeta, $theta) = @{$this}[_F_ORDER, _F_ZETA, _F_THETA];
957 31 $that->[_F_ZETA] =
958 addmod($zeta, mulmod($delta, $order-1, $modulus), $modulus);
959 31 $that->[_F_THETA] = addmod($theta, $delta, $modulus);
960 31 ▶ if (defined (my $e = $that->[_F_ETA])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $e = $that->[5])) 17 14 31
961 17 my $base = $this->[_F_BASE];
962 17 $that->[_F_ETA] =
963 addmod($e, mulmod($delta, $base-1, $modulus), $modulus);
964 }
965 31 return $that;
966 }
967  
968 # $ds2 = $ds->canonize;
969 # $ds2 = $ds->lex_canonize;
970 0 ▶sub lex_canonize {
Subroutine lex_canonize: not called CC=1 SCAR=6.9
Pod documented
971 0 my ($this) = @_;
972 0 my $elements = $this->_elements;
973 0 return $this->translate(- $elements->[$this->[_F_X_START]]);
974 }
975  
976 # $ds2 = $ds->gap_canonize;
977 0 ▶sub gap_canonize {
Subroutine gap_canonize: not called CC=1 SCAR=6.9
Pod documented
978 0 my ($this) = @_;
979 0 my $elements = $this->_elements;
980 0 return $this->translate(- $elements->[$this->[_F_X_GAP]]);
981 }
982  
983 # $ds2 = $ds->zeta_canonize;
984 2 ▶sub zeta_canonize {
Subroutine zeta_canonize: called CC=1 SCAR=0.0
Pod documented
985 2 my ($this) = @_;
986 2 return $this->translate(- $this->[_F_THETA]);
987 }
988  
989 # $it = $ds->iterate_rotators;
990 # while (my $m = $it->()) {
991 # ...
992 # }
993 10 ▶sub iterate_rotators {
Subroutine iterate_rotators: called CC=3 SCAR=15.4
Pod documented
994 10 my ($this, $order, $base, $exponent, $modulus) = _full_params(@_);
995 10 my $rotators = $this->_rotators($order, $base, $exponent, $modulus);
996 10 ▶ return _sequential_rotators($order, $base, $exponent, $modulus)
Branch: 1 branch
BranchTrueFalseTotal
unless $rotators 0 10 10
997 if !$rotators;
998 10 ▶ return _structured_rotators($modulus, $rotators)
Branch: 1 branch
BranchTrueFalseTotal
if "ARRAY" eq ref $rotators->[0] 10 0 10
999 if 'ARRAY' eq ref $rotators->[0];
1000 0 my $mx = 0;
1001 0 ▶ return sub { $mx < @{$rotators}? $rotators->[$mx++]: 0 };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$mx < @{$rotators;} ? : 0 0 0
1002 }
1003  
1004 # $it = $ds->iterate_planes;
1005 # while (my $ds = $it->()) {
1006 # ...
1007 # }
1008 0 ▶sub iterate_planes {
Subroutine iterate_planes: not called CC=1 SCAR=6.9
Pod documented
1009 0 my ($this) = @_;
1010 0 my $r_it = $this->iterate_rotators;
1011 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1012 0 my $r = $r_it->();
1013 0 ▶ return $r? $this->multiply($r)->lex_canonize: undef;
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 0 0 0
1014 0 };
1015 }
1016  
1017 1 ▶sub iterate_planes_zc {
Subroutine iterate_planes_zc: called CC=1 SCAR=0.0
Pod documented
1018 1 my ($this) = @_;
1019 1 my $ref = $this->zeta_canonize;
1020 1 my $r_it = $ref->iterate_rotators;
1021 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
1022 1 my $r = $r_it->();
1023 1 ▶ return $r? $ref->multiply($r): undef;
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 1 0 1
1024 1 };
1025 }
1026  
1027 0 ▶sub iterate_principal_planes {
Subroutine iterate_principal_planes: not called CC=1 SCAR=6.9
Pod documented
1028 0 my ($this) = @_;
1029 0 my $ref = $this->zeta_canonize;
1030 my ( $princ_elems, $modulus) =
1031 0 @{$ref}[_F_PRINC_ELEMS, _F_MODULUS];
1032 0 my $pex = 0;
1033 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1034 0 ▶ return undef if $pex >= @{$princ_elems};
Branch: 1 branch
BranchTrueFalseTotal
if $pex >= @{$princ_elems;} 0 0 0
1035 0 my $r = invmod($princ_elems->[$pex++], $modulus);
1036 0 return $ref->multiply($r)->lex_canonize;
1037 0 };
1038 }
1039  
1040 0 ▶sub iterate_principal_planes_zc {
Subroutine iterate_principal_planes_zc: not called CC=1 SCAR=6.9
Pod documented
1041 0 my ($this) = @_;
1042 0 my $ref = $this->zeta_canonize;
1043 my ( $princ_elems, $modulus) =
1044 0 @{$ref}[_F_PRINC_ELEMS, _F_MODULUS];
1045 0 my $pex = 0;
1046 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1047 0 ▶ return undef if $pex >= @{$princ_elems};
Branch: 1 branch
BranchTrueFalseTotal
if $pex >= @{$princ_elems;} 0 0 0
1048 0 my $r = invmod($princ_elems->[$pex++], $modulus);
1049 0 return $ref->multiply($r);
1050 0 };
1051 }
1052  
1053 # @pm = $ds->multipliers;
1054 2 ▶sub multipliers {
Subroutine multipliers: called CC=3 SCAR=11.0
Pod documented
1055 2 my ($this, $order, $base, $exponent, $modulus) = _full_params(@_);
1056 2 my $n_mult = 3 * $exponent;
1057 2 ▶ return $n_mult if !wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 2 2
1058 2 my @mult = (1, $base);
1059 2 my $x = $base;
1060 2 ▶ while (@mult < $n_mult) {
Branch: 1 branch
BranchTrueFalseTotal
if (@mult < $n_mult) 8 2 10
1061 8 $x = mulmod($x, $base, $modulus);
1062 8 push @mult, $x;
1063 }
1064 2 return @mult;
1065 }
1066  
1067 # $ds3 = $ds->multiply($m);
1068 38 ▶sub multiply {
Subroutine multiply: called CC=12 SCAR=25.5
Pod documented
1069 38 my ($this, $factor) = @_;
1070 my ( $order, $base, $exponent, $modulus) =
1071 38 @{$this}[_F_ORDER, _F_BASE, _F_EXPONENT, _F_MODULUS];
1072 38 $factor %= $modulus;
1073 38 ▶ return $this if 1 == $factor;
Branch: 1 branch
BranchTrueFalseTotal
if 1 == $factor 13 25 38
1074 25 ▶ croak "factor $factor is not coprime to modulus"
Branch: 1 branch
BranchTrueFalseTotal
if &gcd($modulus, $factor) != 1 0 25 25
1075 if gcd($modulus, $factor) != 1;
1076 25 my $theta1 = $this->[_F_THETA];
1077 25 ▶ my $theta = $theta1 && mulmod($theta1, $factor, $modulus);
Condition66%2/3
$theta1 && &mulmod($theta1, $factor, $modulus)
!ll&&!rl&&r
13012
MC/DC50%1/2
$theta1 && &mulmod($theta1, $factor, $modulus)
$theta1 &mulmod($theta1, $factor, $modulus)
Truth table66%2/3
A && B
A= $theta1B= &mulmod($theta1, $factor, $modulus)
ABresult
0X0
100
111
1078 25 my $mult = 3 * $exponent;
1079 25 ▶ return $this->translate($theta - $theta1) if
Branch: 1 branch
BranchTrueFalseTotal
if _is_mult($factor, $base, $mult, $modulus) 0 25 25
1080 _is_mult($factor, $base, $mult, $modulus);
1081 my ( $zeta, $eta, $lambda) =
1082 25 @{$this}[_F_ZETA, _F_ETA, _F_LAMBDA];
1083 25 ▶ $zeta &&= mulmod($zeta, $factor, $modulus);
Condition66%2/3
$zeta &&= &mulmod($zeta, $factor, $modulus)
!ll&&!rl&&r
13012
MC/DC50%1/2
$zeta &&= &mulmod($zeta, $factor, $modulus)
$zeta &mulmod($zeta, $factor, $modulus)
Truth table66%2/3
A &&= B
A= $zetaB= &mulmod($zeta, $factor, $modulus)
ABresult
0X0
100
111
1084 25 ▶ $eta &&= mulmod($eta, $factor, $modulus);
Condition66%2/3
$eta &&= &mulmod($eta, $factor, $modulus)
!ll&&!rl&&r
1906
MC/DC50%1/2
$eta &&= &mulmod($eta, $factor, $modulus)
$eta &mulmod($eta, $factor, $modulus)
Truth table66%2/3
A &&= B
A= $etaB= &mulmod($eta, $factor, $modulus)
ABresult
0X0
100
111
1085 25 my @princ = ();
1086 25 my @suppl = ();
1087 25 foreach my $e (@{$this->[_F_PRINC_ELEMS]}) {
1088 14 my $p0 = my $p = mulmod($e, $factor, $modulus);
1089 14 for (2 .. $mult) {
1090 100 $p = mulmod($p, $base, $modulus);
1091 100 ▶ $p0 = $p if $p0 > $p;
Branch: 1 branch
BranchTrueFalseTotal
if $p0 > $p 0 100 100
1092 }
1093 14 push @princ, $p0;
1094 }
1095 0 @princ = sort { $a <=> $b } @princ;
1096 25 foreach my $e (@{$this->[_F_SUPPL_ELEMS]}) {
1097 11 push @suppl,
1098 _min_factor(mulmod($e, $factor, $modulus), $base, $modulus);
1099 }
1100 0 @suppl = sort { $a <=> $b } @suppl;
1101 25 ▶ if ($lambda) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lambda) 25 0 25
1102 25 $lambda =
1103 _min_factor(mulmod($lambda, $factor, $modulus), $base, $modulus);
1104 }
1105 25 return bless [
1106 $order,
1107 $base,
1108 $exponent,
1109 $modulus,
1110 $zeta,
1111 $eta,
1112 $theta,
1113 \@princ,
1114 \@suppl,
1115 $lambda,
1116 undef, # elements
1117 undef, # index_start
1118 undef, # index_gap
1119 ], ref $this;
1120 }
1121  
1122 # ($e1, $e2) = $ds->find_delta($delta);
1123 42 ▶sub find_delta {
Subroutine find_delta: called CC=10 SCAR=23.1
Pod documented
1124 42 my ($this, $delta) = @_;
1125 42 my $order = $this->order;
1126 42 my $modulus = $this->modulus;
1127 42 my $elements = $this->_elements;
1128 42 my $de = $delta % $modulus;
1129 42 my $up = $de + $de < $modulus;
1130 42 ▶ $de = $modulus - $de if !$up;
Branch: 1 branch
BranchTrueFalseTotal
unless $up 22 20 42
1131 42 my ($lx, $ux, $c) = (0, 0, 0);
1132 42 my ($le, $ue) = @{$elements}[0, 0];
1133 42 my $bogus = 0;
1134 42 ▶ while ($c != $de) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c != $de) 171 42 213
1135 171 ▶ if ($c < $de) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c < $de) { } 125 46 171
1136 125 ▶ if(++$ux > $order) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$ux > $order) 3 122 125
1137 3 $ux = 0;
1138 }
1139 125 $ue = $elements->[$ux];
1140 125 ▶ $bogus = 1, last if $ux == $lx;
Branch: 1 branch
BranchTrueFalseTotal
if $ux == $lx 0 125 125
1141 }
1142 else {
1143 46 ▶ $bogus = 1, last if ++$lx > $order;
Branch: 1 branch
BranchTrueFalseTotal
if ++$lx > $order 0 46 46
1144 46 $le = $elements->[$lx];
1145 }
1146 171 ▶ $c = $ue < $le? $modulus + $ue - $le: $ue - $le;
Branch: 1 branch
BranchTrueFalseTotal
$ue < $le ? : 8 163 171
1147 }
1148 42 ▶ croak "bogus set: delta not found: $delta (mod $modulus)" if $bogus;
Branch: 1 branch
BranchTrueFalseTotal
if $bogus 0 42 42
1149 42 ▶ return $up? ($le, $ue): ($ue, $le);
Branch: 1 branch
BranchTrueFalseTotal
$up ? : 20 22 42
1150 }
1151  
1152 # $e0 = $ds->start_element;
1153 0 ▶sub start_element {
Subroutine start_element: not called CC=1 SCAR=6.9
Pod documented
1154 0 my ($this) = @_;
1155 0 my $elements = $this->_elements;
1156 0 return $elements->[$this->[_F_X_START]];
1157 }
1158  
1159 # ($e1, $e2) = $ds->peak_elements
1160 0 ▶sub peak_elements {
Subroutine peak_elements: not called CC=1 SCAR=6.9
Pod documented
1161 0 my ($this) = @_;
1162 0 return $this->find_delta($this->modulus >> 1);
1163 }
1164  
1165 # ($e1, $e2, $delta) = $ds->largest_gap;
1166 0 ▶sub largest_gap {
Subroutine largest_gap: not called CC=2 SCAR=17.9
Pod documented
1167 0 my ($this) = @_;
1168 0 my $elements = $this->_elements;
1169 0 my $x2 = $this->[_F_X_GAP];
1170 0 my ($e1, $e2) = @{$elements}[$x2 - 1, $x2];
1171 0 ▶ my $delta = $x2? $e2 - $e1: $this->modulus + $e2 - $e1;
Branch: 1 branch
BranchTrueFalseTotal
$x2 ? : 0 0 0
1172 0 return ($e1, $e2, $delta);
1173 }
1174  
1175 # $e = $ds->eta
1176 14 ▶sub eta {
Subroutine eta: called CC=3 SCAR=11.0
Pod documented
1177 14 my ($this) = @_;
1178 14 ▶ return $this->zeta if $this->[_F_EXPONENT] == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $this->[2] == 1 0 14 14
1179 14 my $eta = $this->[_F_ETA];
1180 14 ▶ if (!defined $eta) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $eta) 7 7 14
1181 7 my $p = $this->[_F_BASE];
1182 7 my $m = $this->[_F_MODULUS];
1183 7 my ($x) = $this->find_delta( invmod($p, $m) );
1184 7 my $s = $this->[_F_ELEMENTS]->[$this->[_F_X_START]];
1185 7 $eta = $this->[_F_ETA] = addmod(mulmod($x, $p, $m), -$s, $m);
1186 }
1187 14 return $eta;
1188 }
1189  
1190 0 ▶sub plane_principal_elements { @{$_[0]->[_F_PRINC_ELEMS]} }
Subroutine plane_principal_elements: not called CC=1 SCAR=6.9
Pod documented
1191 0 ▶sub plane_supplemental_elements { @{$_[0]->[_F_SUPPL_ELEMS]} }
Subroutine plane_supplemental_elements: not called CC=1 SCAR=6.9
Pod documented
1192  
1193 0 ▶sub plane_fill_elements {
Subroutine plane_fill_elements: not called CC=1 SCAR=6.9
Pod documented
1194 0 my ($this) = @_;
1195 0 my @fe = _fill_elements(@{$this}[_F_ORDER, _F_MODULUS]);
1196 0 return @fe;
1197 }
1198  
1199 0 ▶sub plane_derived_elements_of {
Subroutine plane_derived_elements_of: not called CC=3 SCAR=24.8
Pod documented
1200 0 my ($this, @elem) = @_;
1201 0 my ($base, $modulus) = @{$this}[_F_BASE, _F_MODULUS];
1202 0 my @de = ();
1203 0 foreach my $e0 (@elem) {
1204 0 my $e = mulmod($e0, $base, $modulus);
1205 0 ▶ while ($e != $e0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e != $e0) 0 0 0
1206 0 push @de, $e;
1207 0 $e = mulmod($e, $base, $modulus);
1208 }
1209 }
1210 0 return @de;
1211 }
1212  
1213 0 ▶sub plane_unit_elements {
Subroutine plane_unit_elements: not called CC=2 SCAR=17.9
Pod documented
1214 0 my ($this) = @_;
1215 0 ▶ if (!wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 0 0
1216 0 return 3 * $this->[_F_EXPONENT] * @{$this->[_F_PRINC_ELEMS]};
1217 }
1218 return
1219 0 map { ($_, $this->plane_derived_elements_of($_)) }
1220 0 @{$this->[_F_PRINC_ELEMS]};
1221 }
1222  
1223 0 ▶sub plane_nonunit_elements {
Subroutine plane_nonunit_elements: not called CC=3 SCAR=24.8
Pod documented
1224 0 my ($this) = @_;
1225 0 ▶ if (!wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 0 0
1226 0 return $this->[_F_ORDER] + 1 - $this->plane_unit_elements;
1227 }
1228 return
1229 (
1230 (
1231 0 map { @{$_} }
1232 0 ▶ sort { @{$b} <=> @{$a} || $a->[0] <=> $b->[0] }
Condition0%0/3
@{$b;} <=> @{$a;} || $Math::DifferenceSet::Planar::a->[0] <=> $Math::DifferenceSet::Planar::b->[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
@{$b;} <=> @{$a;} || $Math::DifferenceSet::Planar::a->[0] <=> $Math::DifferenceSet::Planar::b->[0]
@{$b;} <=> @{$a;} $Math::DifferenceSet::Planar::a->[0] <=> $Math::DifferenceSet::Planar::b->[0]
Truth table0%0/3
A || B
A= @{$b;} <=> @{$a;}B= $Math::DifferenceSet::Planar::a->[0] <=> $Math::DifferenceSet::Planar::b->[0]
ABresult
1X1
011
000
1233 0 map { [$_, $this->plane_derived_elements_of($_)] }
1234 0 @{$this->[_F_SUPPL_ELEMS]}
1235 ),
1236 0 _fill_elements(@{$this}[_F_ORDER, _F_MODULUS])
1237 );
1238 }
1239  
1240 # $bool = $ds->contains($e)
1241 0 ▶sub contains {
Subroutine contains: not called CC=1 SCAR=6.9
Pod documented
1242 0 my ($this, $elem) = @_;
1243 0 my $elements = $this->_elements;
1244 0 return _ol_contains($elements, $elem);
1245 }
1246  
1247 # $cmp = $ds1->compare($ds2);
1248 42 ▶sub compare {
Subroutine compare: called CC=4 SCAR=13.9
Pod documented
1249 42 my ($this, $that) = @_;
1250 42 my $order = $this->order;
1251 42 my $cmp = $order <=> $that->order;
1252 42 ▶ return $cmp if $cmp;
Branch: 1 branch
BranchTrueFalseTotal
if $cmp 6 36 42
1253 36 my $le = $this->_elements;
1254 35 my $re = $that->_elements;
1255 35 foreach my $x (0 .. $order) {
1256 142 $cmp = $le->[$x] <=> $re->[$x];
1257 142 ▶ return $cmp if $cmp;
Branch: 1 branch
BranchTrueFalseTotal
if $cmp 6 136 142
1258 }
1259 29 return 0;
1260 }
1261  
1262 # $cmp = $ds1->compare_topdown($ds2);
1263 16 ▶sub compare_topdown {
Subroutine compare_topdown: called CC=4 SCAR=13.9
Pod documented
1264 16 my ($this, $that) = @_;
1265 16 my $order = $this->order;
1266 16 my $cmp = $order <=> $that->order;
1267 16 ▶ return $cmp if $cmp;
Branch: 1 branch
BranchTrueFalseTotal
if $cmp 6 10 16
1268 10 my $le = $this->_elements;
1269 10 my $re = $that->_elements;
1270 10 my $x = $order;
1271 10 ▶ while ($x >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x >= 0) 19 4 23
1272 19 $cmp = $le->[$x] <=> $re->[$x];
1273 19 ▶ return $cmp if $cmp;
Branch: 1 branch
BranchTrueFalseTotal
if $cmp 6 13 19
1274 13 --$x;
1275 }
1276 4 return 0;
1277 }
1278  
1279 # $bool = $ds1->same_plane($ds2);
1280 16 ▶sub same_plane {
Subroutine same_plane: called CC=7 SCAR=30.0
Pod documented
1281 16 my ($this, $that) = @_;
1282 16 my $order = $this->order;
1283 16 ▶ return !1 if $order != $that->order;
Branch: 1 branch
BranchTrueFalseTotal
if $order != $that->order 6 10 16
1284 10 my $l1 = $this->[_F_LAMBDA];
1285 10 my $l2 = $that->[_F_LAMBDA];
1286 10 ▶ return $l1 == $l2 if $l1 && $l2;
Branch: 1 branch
BranchTrueFalseTotal
if $l1 and $l2 10 0 10
Condition33%1/3
$l1 and $l2
!ll&&!rl&&r
0010
MC/DC0%0/2
$l1 and $l2
$l1 $l2
Truth table33%1/3
A and B
A= $l1B= $l2
ABresult
0X0
100
111
1287 0 my $le = $this->[_F_PRINC_ELEMS];
1288 0 my $re;
1289 0 ▶ if (@{$le}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$le;}) { } 0 0 0
1290 0 $re = $that->[_F_PRINC_ELEMS];
1291 }
1292 else {
1293 0 $le = $this->[_F_SUPPL_ELEMS];
1294 0 $re = $that->[_F_SUPPL_ELEMS];
1295 }
1296 0 foreach my $x (0 .. $#{$le}) {
1297 0 ▶ return !1 if $re->[$x] != $le->[$x];
Branch: 1 branch
BranchTrueFalseTotal
if $re->[$x] != $le->[$x] 0 0 0
1298 }
1299 0 return !0;
1300 }
1301  
1302 # @e = $ds1->common_elements($ds2);
1303 16 ▶sub common_elements {
Subroutine common_elements: called CC=7 SCAR=19.5
Pod documented
1304 16 my ($this, $that) = @_;
1305 16 my $order = $this->order;
1306 16 my @common = ();
1307 16 ▶ return @common if $order != $that->order;
Branch: 1 branch
BranchTrueFalseTotal
if $order != $that->order 6 10 16
1308 10 my $li = 0;
1309 10 my $ri = 0;
1310 10 my $le = $this->_elements;
1311 10 my $re = $that->_elements;
1312 10 my $lv = $le->[0];
1313 10 my $rv = $re->[0];
1314 10 while (1) {
1315 37 my $cmp = $lv <=> $rv;
1316 37 ▶ push @common, $lv if !$cmp;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmp 19 18 37
1317 37 ▶ if ($cmp <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp <= 0) 28 9 37
1318 28 ▶ last if ++$li > $order;
Branch: 1 branch
BranchTrueFalseTotal
if ++$li > $order 7 21 28
1319 21 $lv = $le->[$li];
1320 }
1321 30 ▶ if ($cmp >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp >= 0) 23 7 30
1322 23 ▶ last if ++$ri > $order;
Branch: 1 branch
BranchTrueFalseTotal
if ++$ri > $order 3 20 23
1323 20 $rv = $re->[$ri];
1324 }
1325 }
1326 10 return @common;
1327 }
1328  
1329 # ($factor, $delta) = $ds1->find_linear_map($ds2);
1330 24 ▶sub find_linear_map {
Subroutine find_linear_map: called CC=1 SCAR=0.0
Pod documented
1331 24 my ($this, $that) = @_;
1332 24 my $factor = _find_factor($this, $that);
1333 23 my $delta = _delta_f($this, $factor, $that);
1334 23 return ($factor, $delta);
1335 }
1336  
1337 # @factor_delta_pairs = $ds1->find_all_linear_maps($ds2);
1338 3 ▶sub find_all_linear_maps {
Subroutine find_all_linear_maps: called CC=2 SCAR=6.9
Pod documented
1339 3 my ($this, $that) = @_;
1340 3 my $f1 = eval { _find_factor($this, $that) };
1341 3 ▶ return () if !defined $f1;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f1 1 2 3
1342 2 my $modulus = $this->modulus;
1343 return
1344 18 sort { $a->[0] <=> $b->[0] }
1345 map {
1346 2 my $f = mulmod($f1, $_, $modulus);
1347 12 my $d = _delta_f($this, $f, $that);
1348 12 [$f, $d]
1349 } $this->multipliers;
1350 }
1351  
1352 6 1;
1353 __END__
↑ Summary Planar/Data.pm »