blib/lib/Math/Group/Thompson.pm

filter: Statementstmt 7.5% 11 / 146 Branchbran 0.0% 0 / 84 Conditioncond 0.0% 0 / 63 MC/DCmcdc 0.0% 0 / 35 Subroutinesub 23.0% 3 / 13 Podpod 100% 9 / 9 totaltotal 6.5% 23 / 350 CC 72 SCAR 57.3
CC
72
Cov
4%
cardBn
702.0
multiply
342.0
note
72.0
CRAP 307.8
↑ Summary
1 #
2 # OO methods that calculates #B(n) on Thompson group F
3 #
4 # Author: Roberto Alamos Moreno <ralamosm@cpan.org>
5 #
6 # Copyright (c) 2004 Roberto Alamos Moreno. All rights reserved.
7 # This program is free software; you can redistribute it and/or
8 # modify it under the same terms as Perl itself.
9 #
10 # November 2004. Antofagasta, Chile.
11 #
12 package Math::Group::Thompson;
13  
14 1 $VERSION = '0.96';
15  
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 =head1 NAME
22  
23 Math::Group::Thompson - OO methods that calculates the cardinality
24 of the ball of radius 'n' of Thompson group F
25  
26 =head1 SYNOPSIS
27  
28 use Math::Group::Thompson;
29  
30 my $F = Math::Group::Thompson->new( VERBOSE => 0 );
31 my $card = $F->cardBn(3,'');
32  
33 print "#B(3) = $card\n";
34  
35 =head1 DESCRIPTION
36  
37 The Math::Group::Thompson module provides objetct oriented methods
38 that calculates the cardinality of the ball of radius 'n'
39 of Thompson group F.
40  
41 This module uses the presentation of F
42  
43 F = < A,B | [AB^(-1),A^(-1)BA] = [AB^(-1),A^(-2)BA^2] = e >
44  
45 where A,B are formal symbols, [x,y] is the usual commutator and e
46 is the identity element of F.
47  
48 [x,y] = xyx^(-1)y^(-1)
49  
50 This means that for every g in F, g can be written as word
51  
52 g = a_{1}a_{2} ... a_{n}
53  
54 where all the a_{i} are A,B,A^(-1) or B^(-1) for all i <= n.
55 Internally, Math::Group::Thompson representates A,B,A^(-1),B^(-1) as
56 A,B,C,D respectively.
57  
58 Considering the set S = { A,B,A^(-1),B^(-1) } as a generator set for F.
59 One can define the length function L, as
60  
61 L(g) = min{ n | g can be written as a word with n elements of S }
62  
63 We have to define L(e) = 0
64  
65 With this definition, the ball of radius n of F, can be defined as
66  
67 B(n) = { g in F | L(g) <= n }
68  
69 So, what this module do is to calculate #B(n) or #(gB(n) - B(n)),
70 where g in F, depending on what you need. Note that by definition of S,
71  
72 B(n+1) = (AB(n)-B(n))U(BB(n)-B(n))U(CB(n)-B(n))U(DB(n)-B(n)) U B(n)
73  
74 so
75  
76 #B(n+1) = #(AB(n)-B(n))+#(BB(n)-B(n))+#(CB(n)-B(n))+#(DB(n)-B(n))+#B(n)
77  
78 Also, this module stores some special relations derived from
79 [AB^(-1),A^(-1)BA] = [AB^(-1),A^(-2)BA^2] = e that must me avoided when
80 counting the elements of B(n). For example, from [AB^(-1),A^(-1)BA] = e
81 it can be derived the relations
82  
83 A^(-1)BAA = AB^(-1)A^(-1)BAB
84 A^(-1)BAAB^(-1) = AB^(-1)A^(-1)BA
85  
86 among many other relations. The first relation show us that if
87 we have a word g that contains AB^(-1)A^(-1)BAB it MUST NOT be counted
88 as an element of B(n) for some n, because the word AB^(-1)A^(-1)BAB
89 can be reduced to A^(-1)BAA and this implies that g was already counted
90 as an element of B(n). Second relation tell us that if we have
91 a word w that contains A^(-1)BAAB^(-1) it MUST NOT be counted as an
92 element of B(n) because w was already counted (or will be counted) as
93 and element of B(n).
94  
95 Resuming, relation [AB^(-1),A^(-1)BA] = 1, allow us to derive relations
96 between words with length 4 and length 6, and between words of length 5.
97 And the second relation [AB^(-1),A^(-2)BA^2] = 1 can be used to derive
98 relations between words with length 6 and words with length 8, and
99 between words of length 7.
100  
101 =head1 METHODS
102  
103 =over 4
104  
105 =item new
106  
107 Creates the Thompson object.
108  
109 Usage: my $F = new->Math::Group::Thompson( VERBOSE => $v );
110  
111 Verbose argument tells Math::Group::Thompson whether print every
112 word generated ($v == 1) or not ($v == 0), or store them
113 in a file, where $v is the name of the file (obviously different
114 to 0 or 1). If the verbose file exists it is replaced, so you have to
115 check for its integrity.
116  
117 NOTE:
118 It's not recommend to store the words on a file because for
119 very small values of n, #B(n) or #gB(n)-B(n) are very very large.
120 For example for n = 19, #B(n) ~ 3^n = 1162261467 ~ 1.1 Giga, but
121 the space ocupped by the file will be (in bytes):
122  
123 #B(1) + sum(i=2 to 19){i*(#B(i) - #B(i-1))} =
124  
125 =cut
126 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
127 0 ▶ my $class = shift || undef;
Condition0%0/2
shift() || undef
l!l
00
MC/DC0%0/1
shift() || undef
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
128 0 ▶ if(!defined $class) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $class) 0 0 0
129 0 return undef;
130 }
131  
132 0 my %args = ( VERBOSE => 0, # By default don't print anything
133 @_ );
134  
135 # Inverse elements
136 0 my $inv = { B => 'D', # B is the inverse of B^(-1)
137 A => 'C', # A is the inverse of A^(-1)
138 D => 'B', # B^(-1) is the inverse of B
139 C => 'A', # A^(-1) is the inverse of A
140 };
141  
142 # Prohibited words
143 # Words of length 5
144 0 my @rel5 = (
145 'BAADC',
146 'ABCCD',
147 'AADCD',
148 'BABCC',
149 'ADCDA',
150 'CBABC',
151 'DCDAB',
152 'DCBAB',
153 'CDABC',
154 'ADCBA',
155 );
156  
157 # Words of length 6
158 0 my @rel6 = (
159 'AADCBA',
160 'DAADCB',
161 'CBAADC',
162 'BAADCD',
163 'DABCCB',
164 'CDABCC',
165 'BABCCD',
166 'ABCCDA',
167 'CDAADC',
168 'AADCDA',
169 'ABCCBA',
170 'CBABCC',
171 'CCDAAD',
172 'ADCDAB',
173 'BCCBAA',
174 'DCBABC',
175 'BCCDAA',
176 'DCDABC',
177 'CCBAAD',
178 'ADCBAB',
179 );
180  
181 # Words of length 7
182 0 my @rel7 = (
183 'CBAAADC',
184 'ABCCCDA',
185 'BAAADCC',
186 'AABCCCD',
187 'AAADCCD',
188 'BAABCCC',
189 'AADCCDA',
190 'CBAABCC',
191 'ADCCDAA',
192 'CCBAABC',
193 'DCCDAAB',
194 'DCCBAAB',
195 'CCDAABC',
196 'ADCCBAA',
197 );
198  
199 # Words of length 8
200 0 my @rel8 = (
201 'AADCCBAA',
202 'AAADCCBA',
203 'CCBAAADC',
204 'CBAAADCC',
205 'CDAABCCC',
206 'CCDAABCC',
207 'AABCCCDA',
208 'ABCCCDAA',
209 'DAAADCCB',
210 'BAAADCCD',
211 'DAABCCCB',
212 'BAABCCCD',
213 'CDAAADCC',
214 'AAADCCDA',
215 'AABCCCBA',
216 'CBAABCCC',
217 'CCDAAADC',
218 'AADCCDAA',
219 'ABCCCBAA',
220 'CCBAABCC',
221 'CCCDAAAD',
222 'ADCCDAAB',
223 'BCCCBAAA',
224 'DCCBAABC',
225 'BCCCDAAA',
226 'DCCDAABC',
227 'CCCBAAAD',
228 'ADCCBAAB',
229 );
230  
231  
232 # Define the generator set S = { A,B,A^(-1),B^(-1) }
233 0 my @generators = ('B','A','D','C');
234  
235 # Open filehandle if we have to
236 0 my $fh;
237 0 ▶ if($args{VERBOSE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"VERBOSE"}) 0 0 0
238 0 ▶ if($args{VERBOSE} ne '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"VERBOSE"} ne 1) 0 0 0
239 0 ▶ $fh = new FileHandle ">".$args{VERBOSE} || undef;
Condition0%0/2
'>' . $args{'VERBOSE'} || undef
l!l
00
MC/DC0%0/1
'>' . $args{'VERBOSE'} || undef
'>' . $args{'VERBOSE'}
Truth table0%0/2
A
A= '>' . $args{'VERBOSE'}
Aresult
11
00
240 }
241 }
242  
243 return bless { INV => $inv, # Inverse relations
244 REL => [\@rel5,\@rel6,\@rel7,\@rel8], # Prohibited words
245 GEN => \@generators, # Generator set
246 COUNTER => 0, # Element counter
247 FIRST_ELEMENT => '', # F's element passed to the firs call of method cardBn
248 FIRST_CALL => 1, # Flag of first call to method cardBn
249 VERBOSE => $args{VERBOSE}, # Verbose mode
250 0 FILEHANDLE => \$fh, # Filehandler
251 }, $class;
252 }
253  
254 =item cardBn
255  
256 This method calculates #B(n) or #(gB(n) - B(n)) depending on if
257 the argument passed to the first call of cardBn is '' or not.
258  
259 Usage: my $c = $F->cardBn($radius,$g);
260  
261 where
262  
263 $radius is an integer number >= 0 and
264 $g is an element of F (word written with A,B,C or D).
265  
266 If the first time cardBn is called $g is not equal to '', then
267 cardBn returns the cardinality of the set
268  
269 gB(n) - B(n) = { w in F | w in gB(n) and w not in B(n) }
270  
271 If the firs time cardBn is callen $g is equal to '', then
272 cardBn returns #B(n).
273  
274 This algorithm runs on exponential time because
275 F is of exponential growth (more "exactly", this algorithm is
276 O(3^n) ).
277  
278 =cut
279 0 ▶sub cardBn {
Subroutine cardBn: not called CC=26 SCAR=65.5
Pod documented
280 0 my ($self,$n,$g) = @_;
281 0 ▶ if(!defined $g) { $g = ""; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $g) 0 0 0
282 0 ▶ if(!defined $self || !ref $self || !defined $n || $n < 0 || $n =~ /\D/ || $g =~ /[^ABCD]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self && ref $self && defined $n or $n < 0 or $n =~ /\D/ or $g =~ /[^ABCD]/) 0 0 0
Condition0%0/15
not defined $self && ref $self && defined $n or $n < 0 or $n =~ /\D/ or $g =~ /[^ABCD]/
l!l&&r!l&&!r
000
not defined $self && ref $self && defined $n or $n < 0 or $n =~ /\D/
l!l&&r!l&&!r
000
not defined $self && ref $self && defined $n or $n < 0
l!l&&r!l&&!r
000
defined $self && ref $self && defined $n
!ll&&!rl&&r
000
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/6
not defined $self && ref $self && defined $n or $n < 0 or $n =~ /\D/ or $g =~ /[^ABCD]/
defined $self ref $self defined $n $n < 0 $n =~ /\D/ $g =~ /[^ABCD]/
Truth table0%0/7
not(A and B && C) or D or E or F
A= defined $selfB= ref $selfC= defined $nD= $n < 0E= $n =~ /\D/F= $g =~ /[^ABCD]/
ABCDEFresult
0XXXXX1
10XXXX1
110XXX1
1111XX1
11101X1
1110011
1110000
283 0 return undef;
284 }
285 0 ▶ if($n == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 0) 0 0 0
286 # We have to calculate #B(0) or #(gB(0) - B(0)). In any case is 1
287 0 return 1;
288 }
289  
290 # Check if we are in the first call of cardBn
291 0 ▶ if($self->{FIRST_CALL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"FIRST_CALL"}) 0 0 0
292 # The first element passed to cardBn is $g. Keep it
293 0 ▶ $self->{FIRST_ELEMENT} = $g || '';
Condition0%0/2
$g || ''
l!l
00
MC/DC0%0/1
$g || ''
$g
Truth table0%0/2
A
A= $g
Aresult
11
00
294 0 $self->{FIRST_CALL} = 0;
295 0 ▶ if($self->{FIRST_ELEMENT} eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"FIRST_ELEMENT"} eq "") 0 0 0
296 0 $self->note('e');
297 }
298 }
299  
300 # For every element A,B,A^(-1) and B^(-1)
301 0 for(0..3) {
302 0 ▶ my $aux_g = $self->multiply($g,$self->{GEN}->[$_]) || ''; # Multiple $g by one of the generators
Condition0%0/2
$self->multiply($g, $self->{'GEN'}[$_]) || ''
l!l
00
MC/DC0%0/1
$self->multiply($g, $self->{'GEN'}[$_]) || ''
$self->multiply($g, $self->{'GEN'}[$_])
Truth table0%0/2
A
A= $self->multiply($g, $self->{'GEN'}[$_])
Aresult
11
00
303 0 my $i = 0; # Flag that say if the new word contains
304  
305 # Check if the new word is one letter larger than the previous one
306 0 my ($length_g,$length_auxg) = (0,0);
307 0 ▶ if($g ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($g ne "") 0 0 0
308 0 $length_g += length($g);
309 }
310 0 ▶ if($aux_g ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($aux_g ne "") 0 0 0
311 0 $length_auxg += length($aux_g);
312 }
313 0 ▶ if($length_auxg == ($length_g + 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length_auxg == $length_g + 1) 0 0 0
314 # Check if some prohibited word is in $aux_g
315 0 LOOP: for(5..8) {
316 0 ▶ if($length_auxg >= $_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length_auxg >= $_) 0 0 0
317 # Check if the word contains any prohibited relation
318 0 foreach my $rel (@{$self->{REL}->[$_-5]}) {
319 0 ▶ if($aux_g =~ /$rel$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aux_g =~ /$rel$/) 0 0 0
320 # Prohibited word found
321 0 $i++;
322 0 last LOOP;
323 }
324 }
325 }
326 }
327  
328 # Check if we foun any prohibited word
329 0 ▶ if($i == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) 0 0 0
330 # Determine if we are calculating #B(n) or #(gB(n) - B(n)) where g is the first argument received by cardBn
331 0 ▶ if($self->{FIRST_ELEMENT} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'FIRST_ELEMENT'} ne '') { } 0 0 0
332 # First element wasn't ''. We are calculating #(gB(n) - B(n))
333 0 ▶ if(length($aux_g) < ($n + length($self->{FIRST_ELEMENT}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $aux_g < $n + length($self->{'FIRST_ELEMENT'})) { } 0 0 0
334 0 $self->cardBn($n,$aux_g);
335 } else {
336 # Count this element
337 # Print word if VERBOSE == 1
338 0 $self->note($aux_g);
339 0 $self->{COUNTER}++;
340 }
341 } else {
342 # Count this element
343 # Print word if VERBOSE == 1
344 0 $self->note($aux_g);
345 0 $self->{COUNTER}++;
346  
347 # First element was empty. We are calculating #B(n)
348 0 ▶ if(length($aux_g) < $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $aux_g < $n) 0 0 0
349 # Word's length is < $n, continue
350 0 $self->cardBn($n,$aux_g);
351 }
352 }
353 }
354 }
355 }
356  
357 # Return
358 0 ▶ if($self->{FIRST_ELEMENT} eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'FIRST_ELEMENT'} eq '') { } 0 0 0
359 0 return $self->{COUNTER} + 1; # Returns #B(n). The 1 is for the identity element
360 } else {
361 0 return $self->{COUNTER}; # Returns #(gB(n)-B(n).
362 }
363 }
364  
365 =item reset
366  
367 Resets the counter used on cardBn method, set
368 the FIRST_ELEMENT property at '', and the FIRST_CALL
369 proporty to 1.
370  
371 Usage: $F->reset;
372  
373 =cut
374 0 ▶sub reset {
Subroutine reset: not called CC=3 SCAR=24.8
Pod documented
375 0 ▶ my $self = shift || undef;
Condition0%0/2
shift() || undef
l!l
00
MC/DC0%0/1
shift() || undef
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
376 0 ▶ if(!defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
377 0 return;
378 }
379  
380 0 $self->{COUNTER} = 0;
381 0 $self->{FIRST_ELEMENT} = '';
382 0 $self->{FIRST_CALL} = 1;
383  
384 0 return 1;
385 }
386  
387 =item multiply
388  
389 Multiplication between two words of F. This method
390 considers the inverse relations stored in the attribute
391 INV.
392  
393 Usage: my $mul = $F->multiply($g,$w);
394  
395 where $g and $w are elements of F, and $mul is the
396 result of $g$w.
397  
398 =cut
399 0 ▶sub multiply {
Subroutine multiply: not called CC=18 SCAR=58.3
Pod documented
400 0 my ($self,$g,$h) = @_;
401 0 ▶ if(!defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
402 0 return;
403 }
404 0 ▶ if(!defined $g && !defined $h) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $g || defined $h) { } 0 0 0
elsif ($g eq '' and $h eq '') { } 0 0 0
Condition0%0/3
defined $g || defined $h
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $g || defined $h
defined $g defined $h
Truth table0%0/3
A || B
A= defined $gB= defined $h
ABresult
1X1
011
000
405 0 return undef;
406 ▶ } elsif($g eq '' && $h eq '') {
Condition0%0/3
$g eq "" and $h eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
$g eq "" and $h eq ""
$g eq "" $h eq ""
Truth table0%0/3
A and B
A= $g eq ""B= $h eq ""
ABresult
0X0
100
111
407 0 return undef;
408 }
409 0 ▶ if(!defined $h) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $h) { } 0 0 0
elsif ($h eq '') { } 0 0 0
410 0 return $g;
411 } elsif ($h eq '') {
412 0 return $g;
413 }
414 0 ▶ if(!defined $g) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $g) { } 0 0 0
elsif ($g eq '') { } 0 0 0
415 0 return $h;
416 } elsif($g eq '') {
417 0 return $h;
418 }
419  
420 # Get inverse relations
421 0 my %inv = $self->get_inv;
422  
423 # Multiply
424 0 my @h = split(//,$h);
425 0 foreach my $el (@h) {
426 0 $g =~ /(.)$/;
427 0 ▶ if($1 ne $inv{$el}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 ne $inv{$el}) { } 0 0 0
428 0 return $g.$h;
429 } else {
430 0 $g =~ s/.$//;
431 0 $h =~ s/^.//;
432 }
433  
434 0 ▶ if($g eq '' && $h ne '') {
Branch: 3 branches
BranchTrueFalseTotal
if ($g eq '' and $h ne '') { } 0 0 0
elsif ($h eq '' and $g ne '') { } 0 0 0
elsif ($g eq '' and $h eq '') { } 0 0 0
Condition0%0/3
$g eq "" and $h ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
$g eq "" and $h ne ""
$g eq "" $h ne ""
Truth table0%0/3
A and B
A= $g eq ""B= $h ne ""
ABresult
0X0
100
111
435 0 return $h
436 ▶ } elsif($h eq '' && $g ne '') {
Condition0%0/3
$h eq "" and $g ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
$h eq "" and $g ne ""
$h eq "" $g ne ""
Truth table0%0/3
A and B
A= $h eq ""B= $g ne ""
ABresult
0X0
100
111
437 0 return $g;
438 ▶ } elsif($g eq '' && $h eq '') {
Condition0%0/3
$g eq "" and $h eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
$g eq "" and $h eq ""
$g eq "" $h eq ""
Truth table0%0/3
A and B
A= $g eq ""B= $h eq ""
ABresult
0X0
100
111
439 0 return undef;
440 }
441 }
442 }
443  
444 =item rotate
445  
446 This module receives as argument a word in F and
447 puts the last letter on word in its first place.
448  
449 Usage: $w = 'ABC';
450 $W = $self->rotate($w); # $W is now equal to 'CBA'
451  
452 =cut
453 0 ▶sub rotate {
Subroutine rotate: not called CC=3 SCAR=24.8
Pod documented
454 0 my ($self,$word) = @_;
455 0 ▶ if(!defined $self || !defined $word) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and defined $word) 0 0 0
Condition0%0/3
defined $self and defined $word
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and defined $word
defined $self defined $word
Truth table0%0/3
A and B
A= defined $selfB= defined $word
ABresult
0X0
100
111
456 0 return undef;
457 }
458  
459 0 $word =~ s/(.)$//;
460 0 return $1.$word;
461 }
462  
463 =item inverse
464  
465 This method receives a word in F and returns its inverse.
466  
467 Usage: $w = 'ABC';
468 $W = $self->inverse($w); # $W == 'ADC'
469  
470 =cut
471 0 ▶sub inverse {
Subroutine inverse: not called CC=4 SCAR=30.0
Pod documented
472 0 my ($self,$word) = @_;
473 0 ▶ if(!defined $self || !defined $word) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and defined $word) 0 0 0
Condition0%0/3
defined $self and defined $word
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and defined $word
defined $self defined $word
Truth table0%0/3
A and B
A= defined $selfB= defined $word
ABresult
0X0
100
111
474 0 return undef;
475 }
476  
477 0 my %inv = $self->get_inv;
478 0 my @word = split(//,$word);
479  
480 0 for(0..$#word) {
481 0 $word[$_] = $inv{$word[$_]};
482 }
483  
484 0 $word = join('',@word);
485 0 return reverse $word;
486 }
487  
488 =item divide
489  
490 This method receives a word in F and returns a 2-dimensional
491 array where the first element is the first half
492 of the word, and the second is the inverse of the
493 second half of the word.
494  
495 Usage: $w = 'AABC';
496 ($w1,$w2) = $self->divide($w); # Now $w1 == 'AA' and $w2 == 'AD'
497  
498 =cut
499 0 ▶sub divide {
Subroutine divide: not called CC=3 SCAR=24.8
Pod documented
500 0 my ($self,$word) = @_;
501 0 ▶ if(!defined $self || !defined $word) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and defined $word) 0 0 0
Condition0%0/3
defined $self and defined $word
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and defined $word
defined $self defined $word
Truth table0%0/3
A and B
A= defined $selfB= defined $word
ABresult
0X0
100
111
502 0 return undef;
503 }
504  
505 0 my $largo = length($word);
506 0 my @word = split(//,$word);
507 0 $word = join('',@word[0..($largo/2)-1]);
508 0 my $word2 = join('',@word[($largo/2)..$#word]);
509 0 $word2 = $self->inverse($word2);
510  
511 0 return ($word,$word2);
512 }
513  
514 =item get_inv
515  
516 This method return the hash of inverse relations
517 between the generators elements of F.
518  
519 =cut
520 0 ▶sub get_inv {
Subroutine get_inv: not called CC=3 SCAR=24.8
Pod documented
521 0 ▶ my $self = shift || undef;
Condition0%0/2
shift() || undef
l!l
00
MC/DC0%0/1
shift() || undef
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
522 0 ▶ if(!defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
523 0 return undef;
524 }
525  
526 0 return %{$self->{INV}};
527 }
528  
529 =item note
530  
531 This method prints in STDERR the string received or
532 puts it on the correspondent file.
533  
534 Usage: $F->note('AA'); # Print AA."\n" or store it on a file.
535  
536 =cut
537 0 ▶sub note {
Subroutine note: not called CC=8 SCAR=42.8
Pod documented
538 0 ▶ my $self = shift || undef;
Condition0%0/2
shift() || undef
l!l
00
MC/DC0%0/1
shift() || undef
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
539 0 ▶ if(!defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
540 0 return undef;
541 }
542  
543 0 ▶ my $g = shift || return undef;
Condition0%0/2
shift() || (return undef)
l!l
00
MC/DC0%0/1
shift() || (return undef)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
544  
545 0 ▶ if($self->{VERBOSE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"VERBOSE"}) 0 0 0
546 0 ▶ if($self->{VERBOSE} eq '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'VERBOSE'} eq '1') { } 0 0 0
547 # Print word to STDERR
548 0 print STDERR $g,"\n";
549 } else {
550 # Put word on the correspondent file
551 0 ▶ if($self->{FILEHANDLE} && ref(${$self->{FILEHANDLE}}) eq 'FileHandle') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"FILEHANDLE"} and ref ${$self->{"FILEHANDLE"};} eq "FileHandle") 0 0 0
Condition0%0/3
$self->{"FILEHANDLE"} and ref ${$self->{"FILEHANDLE"};} eq "FileHandle"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"FILEHANDLE"} and ref ${$self->{"FILEHANDLE"};} eq "FileHandle"
$self->{"FILEHANDLE"} ref ${$self->{"FILEHANDLE"};} eq "FileHandle"
Truth table0%0/3
A and B
A= $self->{"FILEHANDLE"}B= ref ${$self->{"FILEHANDLE"};} eq "FileHandle"
ABresult
0X0
100
111
552 0 my $fh = ${$self->{FILEHANDLE}};
553 0 print $fh $g,"\n";
554 }
555 }
556 }
557 }
558  
559 # Destroy function. Closes the filehandle opened in 'new' method (if it was opened).
560 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=7 SCAR=40.3
561 0 ▶ my $self = shift || undef;
Condition0%0/2
shift() || undef
l!l
00
MC/DC0%0/1
shift() || undef
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
562 0 ▶ if(!defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
563 0 return undef;
564 }
565  
566 0 ▶ if($self->{VERBOSE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"VERBOSE"}) 0 0 0
567 0 ▶ if($self->{VERBOSE} ne '1' && ref(${$self->{FILEHANDLE}}) eq 'FileHandle') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"VERBOSE"} ne 1 and ref ${$self->{"FILEHANDLE"};} eq "FileHandle") 0 0 0
Condition0%0/3
$self->{"VERBOSE"} ne 1 and ref ${$self->{"FILEHANDLE"};} eq "FileHandle"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"VERBOSE"} ne 1 and ref ${$self->{"FILEHANDLE"};} eq "FileHandle"
$self->{"VERBOSE"} ne 1 ref ${$self->{"FILEHANDLE"};} eq "FileHandle"
Truth table0%0/3
A and B
A= $self->{"VERBOSE"} ne 1B= ref ${$self->{"FILEHANDLE"};} eq "FileHandle"
ABresult
0X0
100
111
568 0 ▶ ${$self->{FILEHANDLE}}->close if $self->{FILEHANDLE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"FILEHANDLE"} 0 0 0
569 }
570 }
571 }
572  
573 =back 4
574  
575 =head1 BUGS
576  
577 There isn't reported bugs yet, but that doesn't mean that there aren't ;) .
578  
579 =head1 AUTHOR
580  
581 Roberto Alamos Moreno <ralamosm@cpan.org>
582  
583 Thanks to professor Juan Rivera Letelier for his support to my thesis work, and help in the design
584 of cardBn algorithm :) .
585  
586 =head1 COPYRIGHT
587  
588 Copyright (c) 2004 Roberto Alamos Moreno. All rights reserved.
589 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
590  
591 =cut
592 1 1;
↑ Summary