Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Quantum::Superpositions problem

by orange (Beadle)
on Sep 15, 2008 at 12:10 UTC ( [id://711437]=perlquestion: print w/replies, xml ) Need Help??

orange has asked for the wisdom of the Perl Monks concerning the following question:

hello
i refer to the module Quantum::Superpositions
the code
use strict; use warnings; use Quantum::Superpositions; if (any(2)*all(5,6) < 18) { print "True\n" } else {print "False\n"}
return False, but i think it must print True, because 2*5 And 2*6 < 18
i have downloaded the perl6-pugs for windows from
http://jnthn.net/perl6/pugs-win32.zip
and as i have expected it prints True as in the following image:
http://img225.imageshack.us/img225/4386/perl6pugsdn0.jpg
can someone explain this to me.
i am using windows xp , ActivePerl 5.8.8, Quantum::Superpositions v2.02
regards

Replies are listed 'Best First'.
Re: Quantum::Superpositions problem
by grinder (Bishop) on Sep 15, 2008 at 12:41 UTC
Re: Quantum::Superpositions problem
by ikegami (Patriarch) on Sep 15, 2008 at 12:26 UTC
    Bug. In fact, if I run the example in the documentation, I don't get the documented results.
    use strict; use warnings; use Quantum::Superpositions; print(Quantum::Superpositions->VERSION(), "\n"); if (all(1,2,3)*any(5,6) < 21) { print "no alcohol\n"; } if (all(1,2,3)*any(5,6) < 18) { print "no entry\n"; } if (any(1,2,3)*all(5,6) < 18) { print "under-age\n" } print(all(1,2,3)*any(5,6), "\n"); print(all(1,2,3)*any(5,6), "\n"); print(any(1,2,3)*all(5,6), "\n");

    I get:

    2.02 no alcohol no entry all(any(6,5),any(10,12),any(18,15)) all(any(6,5),any(10,12),any(18,15)) any()

    The documentation says I should get:

    2.02 no alcohol under-age all(5,6,10,12,15,18) all(5,6,10,12,15,18) any(5,6,10,12,15,18)

    The bug might have been introduced by this change in 2.00:

    Replaced the cross product with an iterator. this means that any(@these) != all(@those) does not need to generate the full cartesian product up front. The prime sieve (demo/demo_Primes) now runs in reasonable time/memory.

Re: Quantum::Superpositions problem
by moritz (Cardinal) on Sep 15, 2008 at 12:19 UTC
    I don't know about Quantum::Superpositions, but if it tries to implement current Perl 6 semantics, your expression should yield true as you thought.

    any(2) is just the same as 2, so any(2) * all(5, 6) evaluates to all(10, 12), and all(10, 12) < 18 autothreads to all(10 < 18, 12 < 18), which in turn evaluates to all(Bool::True, Bool::True).

    In boolean context that collapses to Bool::True, or in Perl 5 presumable 1.

    So I suspect that QS is either out of date or has a bug.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://711437]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 16:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found