blib/lib/Quantum/Superpositions.pm

filter: Statementstmt 72.6% 284 / 391 Branchbran 57.1% 48 / 84 Conditioncond 51.4% 18 / 35 MC/DCmcdc 19.0% 4 / 21 Subroutinesub 53.5% 82 / 153 Podpod 0.0% 0 / 11 totaltotal 62.7% 436 / 695 CC 71 SCAR 13.4
CC
71
Cov
69%
__ANON__
30.0
__ANON__
12.0
qulop
12.0
CRAP 3.8
↑ Summary
1  
2 package Quantum::Superpositions;
3  
4 ########################################################################
5 # housekeeping
6 ########################################################################
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Class::Multimethods;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $VERSION = '2.03';
14  
15 sub import
16 3 ▶{
Subroutine import: called CC=6 SCAR=17.9
17 {
18 3 my $caller = caller;
19  
20 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 9 *{ $caller . '::' . $_ } = __PACKAGE__->can( $_ )
23 3 for qw( all any eigenstates );
24 }
25  
26 3 my ($class, %quantized) = @_;
27  
28 3 quantize_unary($_,'quop') for @{$quantized{UNARY}};
29 3 quantize_unary($_,'qulop') for @{$quantized{UNARY_LOGICAL}};
30  
31 3 quantize_binary($_,'qbop') for @{$quantized{BINARY}};
32 3 quantize_binary($_,'qblop') for @{$quantized{BINARY_LOGICAL}};
33  
34  
35 3 1
36 }
37  
38 ########################################################################
39 # utility subroutines and package variables
40 #
41 # these are small enough to get lost in the shuffle. easier to put them
42 # up here than loose 'em...
43 ########################################################################
44  
45 # used to print intermediate results if $debug is true.
46  
47 1 my $debug = 0;
48  
49 sub debug
50 0 ▶{
Subroutine debug: not called CC=2 SCAR=17.9
Pod undocumented
51 0 print +(caller(1))[3], "(";
52 0 print +overload::StrVal($_), "," for @_;
53 0 print ")\n";
54 }
55  
56 # cleans up overloaded calls.
57  
58 166 ▶sub swap { $_[2] ? @_[1,0] : @_[0,1] }
Subroutine swap: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 2 164 166
59  
60 # eigencache tracks objects results. destructor has to clean
61 # out the cache. due to overloading this cannot simply use
62 # the $hash{$referent} trick.
63  
64 1 my %eigencache;
65  
66 334 ▶sub DESTROY { delete $eigencache{overload::StrVal($_[0])}; }
Subroutine DESTROY: called CC=1 SCAR=0.0
67  
68 # replaces the cartesian product with an iterator. normal use is
69 # something like:
70 #
71 # my ( $n, $sub ) = iterator \@list1, \@list2
72 #
73 # my @result = map { somefunc @$sub->() } (1..$n );
74 #
75 # note the limit check on $j: this returns an empty list
76 # after the process has iterated once. this allows for
77 # while( @pair = $iter->() ){ ... } and gracefully handles
78 # (0..$count) also.
79  
80 sub iterator
81 4 ▶{
Subroutine iterator: called CC=1 SCAR=0.0
Pod undocumented
82 4 my ( $a, $b ) = ( shift, shift );
83 4 my ( $i, $j ) = ( -1, -1 );
84  
85 # caller gets back ( iterator count, closure ).
86 # the $j test also allows for while or for(;;)
87 # loops testing the return.
88  
89 (
90 @$a * @$b,
91  
92 sub
93 38 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.1
94 38 $i = ++$i % @$a;
95 38 ▶ ++$j unless $i;
Branch: 1 branch
BranchTrueFalseTotal
unless $i 11 27 38
96  
97 38 ▶ $j < @$b ? [ $a->[$i], $b->[$j] ] : ()
Branch: 1 branch
BranchTrueFalseTotal
$j < @$b ? : 38 0 38
98 }
99 )
100  
101 4 }
102  
103  
104 ########################################################################
105 # what users call. the rest of this stuff is generally called
106 # indirectly via multimethods on the contents of the objects.
107  
108 203 ▶sub any { bless [@_], 'Quantum::Superpositions::Disj' }
Subroutine any: called CC=1 SCAR=0.0
Pod undocumented
109 124 ▶sub all { bless [@_], 'Quantum::Superpositions::Conj' }
Subroutine all: called CC=1 SCAR=0.0
Pod undocumented
110  
111 5 ▶sub all_true { bless [@_], 'Quantum::Superpositions::Conj::True' }
Subroutine all_true: called CC=1 SCAR=0.0
Pod undocumented
112  
113  
114 ########################################################################
115 # what the hell do these really do?
116  
117 sub quantize_unary
118 1 ▶{
Subroutine quantize_unary: called CC=3 SCAR=11.4
Pod undocumented
119 1 my ($fullsubname, $type) = @_;
120  
121 1 my ($package,$subname) = m/(.+)::(.+)$/;
122  
123 1 my $caller = caller;
124  
125 1 my $original = "CORE::$subname";
126  
127 1 ▶ if( $package ne 'CORE' )
Branch: 1 branch
BranchTrueFalseTotal
if ($package ne 'CORE') { } 0 1 1
128 {
129 0 $original = "Quantum::Superpositions::Quantized::$fullsubname";
130  
131 1 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
132  
133 0 *{$original} = \&$fullsubname;
134 }
135 else
136 {
137 1 $package = 'CORE::GLOBAL';
138 }
139  
140 eval
141 0 ▶ qq{
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine __ANON__: called CC=3 SCAR=11.3
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 2 branches
BranchTrueFalseTotal
eval qq[\n\t\tpackage $package;\n\n\t\tuse subs '${subname}';\n\n\t\tuse Class::Multimethods '${type}';\n\t\tlocal \$SIG{__WARN__} = sub{};\n\n\t\tno strict 'refs';\n\n\t\t*{"${package}::$subname"} =\n\t\tsub\n\t\t{\n\t\t\tlocal \$^W;\n\t\t\treturn \$_[0]->$type(sub{$original(\$_[0])})\n\t\t\t if UNIVERSAL::isa(\$_[0],'Quantum::Superpositions')\n\t\t\t || UNIVERSAL::isa(\$_[1],'Quantum::Superpositions');\n\n\t\t\tno strict 'refs';\n\n\t\t\treturn $original(\$_[0]);\n\t\t};\n\t] or croak("Internal error: $@") 1 0 1
if UNIVERSAL::isa($_[0], "Quantum::Superpositions") or UNIVERSAL::isa($_[1], "Quantum::Superpositions") 1 0 1
Condition33%1/3
UNIVERSAL::isa($_[0], "Quantum::Superpositions") or UNIVERSAL::isa($_[1], "Quantum::Superpositions")
l!l&&r!l&&!r
100
MC/DC0%0/2
UNIVERSAL::isa($_[0], "Quantum::Superpositions") or UNIVERSAL::isa($_[1], "Quantum::Superpositions")
UNIVERSAL::isa($_[0], "Quantum::Superpositions") UNIVERSAL::isa($_[1], "Quantum::Superpositions")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($_[0], "Quantum::Superpositions")B= UNIVERSAL::isa($_[1], "Quantum::Superpositions")
ABresult
1X1
011
000
142 package $package;
143  
144 use subs '$subname';
145  
146 use Class::Multimethods '$type';
147 local \$SIG{__WARN__} = sub{};
148  
149 no strict 'refs';
150  
151 *{"${package}::$subname"} =
152 sub
153 {
154 local \$^W;
155 return \$_[0]->$type(sub{$original(\$_[0])})
156 if UNIVERSAL::isa(\$_[0],'Quantum::Superpositions')
157 || UNIVERSAL::isa(\$_[1],'Quantum::Superpositions');
158  
159 no strict 'refs';
160  
161 return $original(\$_[0]);
162 };
163 }
164 || croak "Internal error: $@";
165 }
166  
167 sub quantize_binary
168 2 ▶{
Subroutine quantize_binary: called CC=3 SCAR=11.0
Pod undocumented
169 2 my ($fullsubname, $type) = @_;
170 2 my ($package,$subname) = m/(.*)::(.*)/;
171 2 my $caller = caller;
172 2 my $original = "CORE::$subname";
173 2 ▶ if ($package ne 'CORE')
Branch: 1 branch
BranchTrueFalseTotal
if ($package ne 'CORE') { } 1 1 2
174 {
175 1 $original = "Quantum::Superpositions::Quantized::$fullsubname";
176  
177 1 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
178  
179 1 *{$original} = \&$fullsubname;
180 }
181 else
182 {
183 1 $package = 'CORE::GLOBAL';
184 }
185 eval
186 0 ▶ qq{
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=3 SCAR=11.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=3 SCAR=11.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 3 branches
BranchTrueFalseTotal
eval qq[\n\t\tpackage $package;\n\t\tuse subs '${subname}';\n\n\t\tuse Class::Multimethods '${type}';\n\n\t\tlocal \$SIG{__WARN__} = sub{};\n\n\t\tno strict 'refs';\n\n\t\t*{"${package}::$subname"} =\n\t\tsub\n\t\t{\n\t\t\tlocal \$^W;\n\t\t\treturn $type(\@_[0,1],sub{$original(\$_[0],\$_[1])})\n\t\t\t if UNIVERSAL::isa(\$_[0],'Quantum::Superpositions')\n\t\t\t || UNIVERSAL::isa(\$_[1],'Quantum::Superpositions');\n\n\t\t\tno strict 'refs';\n\n\t\t\treturn $original(\$_[0],\$_[1]);\n\t\t};\n\t] or croak("Internal error: $@") 2 0 2
if UNIVERSAL::isa($_[0], "Quantum::Superpositions") or UNIVERSAL::isa($_[1], "Quantum::Superpositions") 4 3 7
if UNIVERSAL::isa($_[0], "Quantum::Superpositions") or UNIVERSAL::isa($_[1], "Quantum::Superpositions") 2 0 2
Condition66%4/6
UNIVERSAL::isa($_[0], "Quantum::Superpositions") or UNIVERSAL::isa($_[1], "Quantum::Superpositions")
l!l&&r!l&&!r
313
UNIVERSAL::isa($_[0], "Quantum::Superpositions") or UNIVERSAL::isa($_[1], "Quantum::Superpositions")
l!l&&r!l&&!r
200
MC/DC100%2/2
UNIVERSAL::isa($_[0], "Quantum::Superpositions") or UNIVERSAL::isa($_[1], "Quantum::Superpositions")
UNIVERSAL::isa($_[0], "Quantum::Superpositions") UNIVERSAL::isa($_[1], "Quantum::Superpositions")
MC/DC0%0/2
UNIVERSAL::isa($_[0], "Quantum::Superpositions") or UNIVERSAL::isa($_[1], "Quantum::Superpositions")
UNIVERSAL::isa($_[0], "Quantum::Superpositions") UNIVERSAL::isa($_[1], "Quantum::Superpositions")
Truth table100%3/3
A or B
A= UNIVERSAL::isa($_[0], "Quantum::Superpositions")B= UNIVERSAL::isa($_[1], "Quantum::Superpositions")
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= UNIVERSAL::isa($_[0], "Quantum::Superpositions")B= UNIVERSAL::isa($_[1], "Quantum::Superpositions")
ABresult
1X1
011
000
187 package $package;
188 use subs '$subname';
189  
190 use Class::Multimethods '$type';
191  
192 local \$SIG{__WARN__} = sub{};
193  
194 no strict 'refs';
195  
196 *{"${package}::$subname"} =
197 sub
198 {
199 local \$^W;
200 return $type(\@_[0,1],sub{$original(\$_[0],\$_[1])})
201 if UNIVERSAL::isa(\$_[0],'Quantum::Superpositions')
202 || UNIVERSAL::isa(\$_[1],'Quantum::Superpositions');
203  
204 no strict 'refs';
205  
206 return $original(\$_[0],\$_[1]);
207 };
208 } || croak "Internal error: $@";
209 }
210  
211 ########################################################################
212 # assign the multimethods operations for various types
213  
214 multimethod qbop =>
215 ( qw(
216 Quantum::Superpositions::Conj
217 Quantum::Superpositions::Conj
218 CODE
219  
220 ) ) =>
221 sub
222 1 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
223 1 my ( $count, $iter ) = iterator @_[0,1];
224  
225 1 all map { qbop(@{$iter->()}, $_[2]) } (1..$count);
226 1 };
227  
228 multimethod qbop =>
229 ( qw(
230 Quantum::Superpositions::Disj
231 Quantum::Superpositions::Disj
232 CODE
233 ) ) =>
234 sub
235 1 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
236 1 my ( $count, $iter ) = iterator( @_[0,1] );
237  
238 1 any map { qbop(@{$iter->()}, $_[2]) } (1..$count);
239 1 };
240  
241 multimethod qbop =>
242 ( qw(
243 Quantum::Superpositions::Conj
244 Quantum::Superpositions::Disj
245 CODE
246 ) ) =>
247 sub
248 1 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
249 1 all map { qbop($_, $_[1], $_[2]) } @{$_[0]};
250 1 };
251  
252 multimethod qbop =>
253 ( qw(
254 Quantum::Superpositions::Disj
255 Quantum::Superpositions::Conj
256 CODE
257 ) ) =>
258 sub
259 0 ▶{
Subroutine __ANON__: not called CC=1 SCAR=6.9
260 0 any map { qbop($_, $_[1], $_[2]) } @{$_[0]}
261 1 };
262  
263 multimethod qbop =>
264 ( qw(
265 Quantum::Superpositions::Conj
266 *
267 CODE
268 ) ) =>
269 sub
270 0 ▶{
Subroutine __ANON__: not called CC=1 SCAR=6.9
271 0 all map { qbop($_, $_[1], $_[2]) } @{$_[0]}
272 1 };
273  
274 multimethod qbop =>
275 ( qw(
276 Quantum::Superpositions::Disj
277 *
278 CODE
279 ) ) =>
280 sub
281 1 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
282 1 any map { qbop($_, $_[1], $_[2]) } @{$_[0]}
283 1 };
284  
285 multimethod qbop =>
286 ( qw(
287 *
288 Quantum::Superpositions::Disj
289 CODE
290 ) ) =>
291 sub
292 6 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
293 6 any map { qbop($_[0], $_, $_[2]) } @{$_[1]}
294 1 };
295  
296 multimethod qbop =>
297 ( qw(
298 *
299 Quantum::Superpositions::Conj
300 CODE
301 ) ) =>
302 sub
303 0 ▶{
Subroutine __ANON__: not called CC=1 SCAR=6.9
304 0 all map { qbop($_[0], $_, $_[2]) } @{$_[1]}
305 1 };
306  
307 multimethod qbop =>
308 ( qw(
309 *
310 *
311 CODE
312 ) ) =>
313 sub
314 4080 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
315 4080 $_[2]->(@_[0..1])
316 1 };
317  
318 multimethod qblop =>
319 ( qw(
320 Quantum::Superpositions::Conj
321 Quantum::Superpositions::Conj
322 CODE
323 ) ) =>
324 sub
325 2 ▶{
Subroutine __ANON__: called CC=6 SCAR=19.1
326 2 ▶ &debug if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
327  
328 2 ▶ return all() unless @{$_[0]} && @{$_[1]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_[0];} and @{$_[1];} 0 2 2
Condition33%1/3
@{$_[0];} and @{$_[1];}
!ll&&!rl&&r
002
MC/DC0%0/2
@{$_[0];} and @{$_[1];}
@{$_[0];} @{$_[1];}
Truth table33%1/3
A and B
A= @{$_[0];}B= @{$_[1];}
ABresult
0X0
100
111
329  
330 2 my ( $count, $iter ) = iterator @_[0,1];
331  
332 2 ▶ istrue( qblop(@{$iter->()}, $_[2]) ) || return all() for (1..$count);
Branch: 1 branch
BranchTrueFalseTotal
istrue(qblop(@{&$iter();}, $_[2])) or return all() 18 0 18
333  
334 2 all_true @{$_[0]};
335 1 };
336  
337 multimethod qblop =>
338 ( qw(
339 Quantum::Superpositions::Conj
340 Quantum::Superpositions::Disj
341 CODE
342 ) ) =>
343 sub
344 6 ▶{
Subroutine __ANON__: called CC=9 SCAR=22.4
345 6 ▶ &debug if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 6 6
346  
347 6 ▶ return all() unless @{$_[0]} && @{$_[1]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_[0];} and @{$_[1];} 0 6 6
Condition33%1/3
@{$_[0];} and @{$_[1];}
!ll&&!rl&&r
006
MC/DC0%0/2
@{$_[0];} and @{$_[1];}
@{$_[0];} @{$_[1];}
Truth table33%1/3
A and B
A= @{$_[0];}B= @{$_[1];}
ABresult
0X0
100
111
348  
349 6 my @cstates = @{$_[0]};
350  
351 6 my @matchstates;
352  
353 6 my $okay = 0;
354  
355 6 for my $cstate ( @cstates )
356 {
357 27 for my $dstate ( @{$_[1]} )
358 {
359 49 ▶ ++$okay && last
Branch: 1 branch
BranchTrueFalseTotal
if istrue(qblop($cstate, $dstate, $_[2])) 22 27 49
Condition75%3/4
istrue(qblop($cstate, $dstate, $_[2])) && (++$okay && (last))
!ll
2722
++$okay and last
!ll
022
MC/DC0%0/2
istrue(qblop($cstate, $dstate, $_[2])) && (++$okay && (last))
istrue(qblop($cstate, $dstate, $_[2])) ++$okay
Truth table33%1/3
A && B
A= istrue(qblop($cstate, $dstate, $_[2]))B= ++$okay
ABresult
0X0
100
111
360 if istrue(qblop($cstate, $dstate, $_[2]));
361 }
362 }
363  
364 6 ▶ return all() unless $okay == @cstates;
Branch: 1 branch
BranchTrueFalseTotal
unless $okay == @cstates 3 3 6
365 3 return all_true @{$_[0]};
366 1 };
367  
368 multimethod qblop =>
369 ( qw(
370 Quantum::Superpositions::Disj
371 Quantum::Superpositions::Conj
372 CODE
373 ) ) =>
374 sub
375 4 ▶{
Subroutine __ANON__: called CC=8 SCAR=21.1
376 4 ▶ &debug if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 4 4
377  
378 4 ▶ return any() unless @{$_[0]} && @{$_[1]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_[0];} and @{$_[1];} 0 4 4
Condition33%1/3
@{$_[0];} and @{$_[1];}
!ll&&!rl&&r
004
MC/DC0%0/2
@{$_[0];} and @{$_[1];}
@{$_[0];} @{$_[1];}
Truth table33%1/3
A and B
A= @{$_[0];}B= @{$_[1];}
ABresult
0X0
100
111
379  
380 4 my @dstates = @{$_[0]};
381 4 my @cstates = @{$_[1]};
382  
383 4 my @dokay = (0) x @dstates;
384 4 for my $cstate ( @cstates )
385 {
386 12 my $matched;
387 12 for my $d ( 0..$#dstates )
388 {
389 39 ▶ $matched = ++$dokay[$d]
Branch: 1 branch
BranchTrueFalseTotal
if istrue(qblop($dstates[$d], $cstate, $_[2])) 18 21 39
390 if istrue(qblop($dstates[$d], $cstate, $_[2]));
391 }
392  
393 12 ▶ return any() unless $matched;
Branch: 1 branch
BranchTrueFalseTotal
unless $matched 2 10 12
394 }
395  
396 2 return any @dstates[grep { $dokay[$_] == @cstates } (0..$#dstates)];
397 1 };
398  
399 multimethod qblop =>
400 ( qw(
401 Quantum::Superpositions::Conj
402 *
403 CODE
404 ) ) =>
405 sub
406 92 ▶{
Subroutine __ANON__: called CC=5 SCAR=17.5
407 92 ▶ &debug if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 92 92
408  
409 92 ▶ return all() unless @{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_[0];} 0 92 92
410 92 ▶ istrue(qblop($_, $_[1], $_[2])) || return all() for @{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
istrue(qblop($_, $_[1], $_[2])) or return all() 40 92 132
411 0 return all_true @{$_[0]};
412 1 };
413  
414 multimethod qblop =>
415 ( qw(
416 *
417 Quantum::Superpositions::Conj
418 CODE
419 ) ) =>
420 sub
421 0 ▶{
Subroutine __ANON__: not called CC=5 SCAR=34.0
422 0 ▶ &debug if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
423  
424 0 ▶ return all() unless @{$_[1]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_[1];} 0 0 0
425 0 ▶ istrue(qblop($_[0], $_, $_[2])) || return all() for @{$_[1]};
Branch: 1 branch
BranchTrueFalseTotal
istrue(qblop($_[0], $_, $_[2])) or return all() 0 0 0
426 0 return all_true $_[0];
427 1 };
428  
429 multimethod qblop =>
430 ( qw(
431 Quantum::Superpositions::Disj
432 *
433 CODE
434 ) ) =>
435 sub
436 157 ▶{
Subroutine __ANON__: called CC=3 SCAR=11.2
437 157 ▶ &debug if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 157 157
438  
439 157 ▶ return any() unless @{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_[0];} 0 157 157
440 157 return any grep { istrue(qblop($_, $_[1], $_[2])) } @{$_[0]};
441 1 };
442  
443 multimethod qblop =>
444 ( qw(
445 *
446 Quantum::Superpositions::Disj
447 CODE
448 ) ) =>
449 sub
450 0 ▶{
Subroutine __ANON__: not called CC=3 SCAR=24.8
451 0 ▶ &debug if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
452  
453 0 ▶ return any() unless @{$_[1]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_[1];} 0 0 0
454 0 return any grep { istrue(qblop($_[0], $_, $_[2])) } @{$_[1]};
455 1 };
456  
457 multimethod qblop =>
458 ( qw(
459 Quantum::Superpositions::Disj
460 Quantum::Superpositions::Disj
461 CODE
462 ) ) =>
463 sub
464 1 ▶{
Subroutine __ANON__: called CC=4 SCAR=14.8
465 1 ▶ &debug if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
466  
467 1 ▶ return any() unless @{$_[0]} && @{$_[1]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_[0];} and @{$_[1];} 0 1 1
Condition33%1/3
@{$_[0];} and @{$_[1];}
!ll&&!rl&&r
001
MC/DC0%0/2
@{$_[0];} and @{$_[1];}
@{$_[0];} @{$_[1];}
Truth table33%1/3
A and B
A= @{$_[0];}B= @{$_[1];}
ABresult
0X0
100
111
468 1 return any grep { istrue(qblop($_[0], $_, $_[2])) } @{$_[1]};
469 1 };
470  
471 multimethod qblop =>
472 ( qw(
473 *
474 *
475 CODE
476 ) ) =>
477 sub
478 3929 ▶{
Subroutine __ANON__: called CC=3 SCAR=11.1
479 3929 ▶ &debug if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 3929 3929
480  
481 3929 ▶ return qbop(@_) ? $_[0] : ();
Branch: 1 branch
BranchTrueFalseTotal
qbop(@_) ? : 188 3741 3929
482 1 };
483  
484 ########################################################################
485 # overload everything possible into appropraite multimethods.
486 # this is where the limitation for regexen hits.
487  
488 use overload
489  
490 0 ▶ q{+} => sub { qbop(swap(@_), sub { $_[0] + $_[1] })},
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
491 0 ▶ q{-} => sub { qbop(swap(@_), sub { $_[0] - $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
492 2 ▶ q{*} => sub { qbop(swap(@_), sub { $_[0] * $_[1] })},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
493 2 ▶ q{/} => sub { qbop(swap(@_), sub { $_[0] / $_[1] })},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
494 0 ▶ q{%} => sub { qbop(swap(@_), sub { $_[0] % $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
495 0 ▶ q{**} => sub { qbop(swap(@_), sub { $_[0] ** $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
496 0 ▶ q{<<} => sub { qbop(swap(@_), sub { $_[0] << $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
497 0 ▶ q{>>} => sub { qbop(swap(@_), sub { $_[0] >> $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
498 0 ▶ q{x} => sub { qbop(swap(@_), sub { $_[0] x $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
499 0 ▶ q{.} => sub { qbop(swap(@_), sub { $_[0] . $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
500 0 ▶ q{&} => sub { qbop(swap(@_), sub { $_[0] & $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
501 0 ▶ q{^} => sub { qbop(swap(@_), sub { $_[0] ^ $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
502 0 ▶ q{|} => sub { qbop(swap(@_), sub { $_[0] | $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
503 0 ▶ q{atan2}=> sub { qbop(swap(@_), sub { atan2($_[0],$_[1]) })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
504  
505 5 ▶ q{<} => sub { qblop(swap(@_), sub { $_[0] < $_[1] })},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
506 0 ▶ q{<=} => sub { qblop(swap(@_), sub { $_[0] <= $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
507 5 ▶ q{>} => sub { qblop(swap(@_), sub { $_[0] > $_[1] })},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
508 0 ▶ q{>=} => sub { qblop(swap(@_), sub { $_[0] >= $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
509 47 ▶ q{==} => sub { qblop(swap(@_), sub { $_[0] == $_[1] })},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
510 2 ▶ q{!=} => sub { qblop(swap(@_), sub { $_[0] != $_[1] })},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
511 0 ▶ q{<=>} => sub { qblop(swap(@_), sub { $_[0] <=> $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
512 0 ▶ q{lt} => sub { qblop(swap(@_), sub { $_[0] lt $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
513 0 ▶ q{le} => sub { qblop(swap(@_), sub { $_[0] le $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
514 0 ▶ q{gt} => sub { qblop(swap(@_), sub { $_[0] gt $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
515 0 ▶ q{ge} => sub { qblop(swap(@_), sub { $_[0] ge $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
516 103 ▶ q{eq} => sub { qblop(swap(@_), sub { $_[0] eq $_[1] })},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
517 0 ▶ q{ne} => sub { qblop(swap(@_), sub { $_[0] ne $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
518 0 ▶ q{cmp} => sub { qblop(swap(@_), sub { $_[0] cmp $_[1] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
519  
520 0 ▶ q{cos} => sub { $_[0]->quop(sub { cos $_[0] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
521 0 ▶ q{sin} => sub { $_[0]->quop(sub { sin $_[0] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
522 0 ▶ q{exp} => sub { $_[0]->quop(sub { exp $_[0] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
523 0 ▶ q{abs} => sub { $_[0]->quop(sub { abs $_[0] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
524 0 ▶ q{sqrt} => sub { $_[0]->quop(sub { sqrt $_[0] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
525 0 ▶ q{log} => sub { $_[0]->quop(sub { log $_[0] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
526 0 ▶ q{neg} => sub { $_[0]->quop(sub { -$_[0] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
527 0 ▶ q{~} => sub { $_[0]->quop(sub { ~$_[0] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
528  
529 q{&{}} =>
530 sub
531 2 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
532 2 my $s = shift;
533 2 ▶ return sub { bless [map {$_->(@_)} @$s], ref $s }
Subroutine __ANON__: called CC=1 SCAR=0.0
534 2 },
535  
536 0 ▶ q{!} => sub { $_[0]->qulop(sub { !$_[0] })},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
537  
538 1 q{bool} => 'qbool',
539 q{""} => 'qstr',
540 q{0+} => 'qnum',
541 1 ;
542  
543 ########################################################################
544 # extract results from the Q::S objects.
545  
546 multimethod collapse =>
547 ( 'Quantum::Superpositions' ) =>
548 52 ▶ sub { return map { collapse($_) } @{$_[0]} };
Subroutine __ANON__: called CC=1 SCAR=0.0
549  
550 113 ▶multimethod collapse => ( '*' ) => sub { return $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
551  
552 sub eigenstates($)
553 77 ▶{
Subroutine eigenstates: called CC=4 SCAR=14.0
Pod undocumented
554 77 my ($self) = @_;
555 77 my $eigencache_id = overload::StrVal($self);
556 31 return @{$eigencache{$eigencache_id}}
557 77 ▶ if defined $eigencache{$eigencache_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $eigencache{$eigencache_id} 31 46 77
558 46 my %uniq;
559 46 @uniq{collapse($self)} = ();
560 46 local $^W=1;
561 46 return @{$eigencache{$eigencache_id}} =
562 grep
563 {
564 46 my $okay=1;
565 103 ▶ local $SIG{__WARN__} = sub {$okay=0};
Subroutine __ANON__: called CC=1 SCAR=0.0
566 103 ▶ istrue($self eq $_) || istrue($self == $_) && $okay
Condition50%3/6
istrue($self eq $_) || istrue($self == $_) && $okay
l!l&&r!l&&!r
57046
istrue($self == $_) and $okay
!ll&&!rl&&r
4600
MC/DC33%1/3
istrue($self eq $_) || istrue($self == $_) && $okay
istrue($self eq $_) istrue($self == $_) $okay
Truth table50%2/4
A || B and C
A= istrue($self eq $_)B= istrue($self == $_)C= $okay
ABCresult
1XX1
0111
00X0
0100
567 }
568 keys %uniq;
569 }
570  
571 multimethod istrue => ( 'Quantum::Superpositions::Disj' ) =>
572 sub
573 155 ▶ {
Subroutine __ANON__: called CC=4 SCAR=14.5
574 155 ▶ my @states = @{$_[0]} || return 0;
Condition100%2/2
@{$_[0];} || (return 0)
l!l
8372
MC/DC100%1/1
@{$_[0];} || (return 0)
@{$_[0];}
Truth table100%2/2
A
A= @{$_[0];}
Aresult
11
00
575 0 ▶ istrue($_) && return 1 for @states; return 0;
Branch: 1 branch
BranchTrueFalseTotal
istrue($_) and return 1 83 0 83
576 1 };
577  
578 multimethod istrue => ( 'Quantum::Superpositions::Conj::True' ) =>
579 0 ▶ sub { return 1; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
580  
581 multimethod istrue => ( 'Quantum::Superpositions::Conj' ) =>
582 sub
583 92 ▶ {
Subroutine __ANON__: called CC=4 SCAR=20.7
584 92 ▶ my @states = @{$_[0]} || return 0;
Condition50%1/2
@{$_[0];} || (return 0)
l!l
092
MC/DC0%0/1
@{$_[0];} || (return 0)
@{$_[0];}
Truth table50%1/2
A
A= @{$_[0];}
Aresult
11
00
585 0 ▶ istrue($_) || return 0 for @states; return 1;
Branch: 1 branch
BranchTrueFalseTotal
istrue($_) or return 0 0 0 0
586 1 };
587  
588 271 ▶multimethod istrue => ( '*' ) => sub { return defined $_[0]; };
Subroutine __ANON__: called CC=1 SCAR=0.0
589  
590 3741 ▶multimethod istrue => () => sub { return 0; };
Subroutine __ANON__: called CC=1 SCAR=0.0
591  
592 15 ▶sub qbool { $_[0]->eigenstates ? 1 : 0; }
Subroutine qbool: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->eigenstates ? : 8 7 15
593 0 ▶sub qnum { my @states = $_[0]->eigenstates; return $states[rand @states] }
Subroutine qnum: not called CC=1 SCAR=6.9
Pod undocumented
594  
595 ########################################################################
596 ########################################################################
597 # embedded classes.
598 #
599 # these are what the constructors bless things into.
600 ########################################################################
601  
602 package Quantum::Superpositions::Disj;
603 1 ▶use base 'Quantum::Superpositions';
Subroutine BEGIN: called CC=1 SCAR=0.0
604 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
605  
606 sub qstr
607 39 ▶{
Subroutine qstr: called CC=2 SCAR=6.9
608 39 my @eigenstates = $_[0]->eigenstates;
609 39 ▶ return "@eigenstates" if @eigenstates == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @eigenstates == 1 7 32 39
610 32 return "any(".join(",",@eigenstates).")"
611 }
612  
613 1 ▶sub quop { Quantum::Superpositions::any(map { $_[1]->($_) } @{$_[0]}) }
Subroutine quop: called CC=1 SCAR=0.0
614  
615 0 ▶sub qulop { Quantum::Superpositions::any(grep { $_[1]->($_) } @{$_[0]}) }
Subroutine qulop: not called CC=1 SCAR=6.9
616  
617  
618 package Quantum::Superpositions::Conj;
619 1 ▶use base 'Quantum::Superpositions';
Subroutine BEGIN: called CC=1 SCAR=0.0
620 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
621  
622 sub qstr
623 22 ▶{
Subroutine qstr: called CC=2 SCAR=7.1
624 22 my @eigenstate = $_[0]->eigenstates;
625  
626 22 ▶ @eigenstate ? "@eigenstate" : "all(".join(",",@{$_[0]}).")"
Branch: 1 branch
BranchTrueFalseTotal
@eigenstate ? : 0 22 22
627 }
628  
629 0 ▶sub quop { return Quantum::Superpositions::all(map { $_[1]->($_) } @{$_[0]}) }
Subroutine quop: not called CC=1 SCAR=6.9
630  
631 sub qulop
632 0 ▶{
Subroutine qulop: not called CC=3 SCAR=24.8
633 0 ▶ $_[1]->($_) || return Quantum::Superpositions::all() for @{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->($_) or return Quantum::Superpositions::all() 0 0 0
634  
635 0 Quantum::Superpositions::all(@{$_[0]})
636 }
637  
638  
639 package Quantum::Superpositions::Conj::True;
640 1 ▶use base 'Quantum::Superpositions::Conj';
Subroutine BEGIN: called CC=1 SCAR=0.0
641  
642 5 ▶sub qbool { 1 }
Subroutine qbool: called CC=1 SCAR=0.0
643  
644  
645 1 1;
646  
647 __END__
↑ Summary