Package Info

perl-Quantum-Superpositions


QM-like superpositions in Perl


Development/Libraries/Perl

The Quantum::Superpositions module adds two new operators to Perl: 'any' and 'all'.

Each of these operators takes a list of values (states) and superimposes them into a single scalar value (a superposition), which can then be stored in a standard scalar variable.

The 'any' and 'all' operators produce two distinct kinds of superposition. The 'any' operator produces a disjunctive superposition, which may (notionally) be in any one of its states at any time, according to the needs of the algorithm that uses it.

In contrast, the 'all' operator creates a conjunctive superposition, which is always in every one of its states simultaneously.

Superpositions are scalar values and hence can participate in arithmetic and logical operations just like any other type of scalar. However, when an operation is applied to a superposition, it is applied (notionally) in parallel to each of the states in that superposition.

For example, if a superposition of states 1, 2, and 3 is multiplied by 2:

$result = any(1,2,3) * 2;

the result is a superposition of states 2, 4, and 6. If that result is then compared with the value 4:

if ($result == 4) { print "fore!" }

then the comparison also returns a superposition: one that is both true and false (since the equality is true for one of the states of '$result' and false for the other two).

Of course, a value that is both true and false is of no use in an 'if' statement, so some mechanism is needed to decide which superimposed boolean state should take precedence.

This mechanism is provided by the two types of superposition available. A disjunctive superposition is true if any of its states is true, whereas a conjunctive superposition is true only if all of its states are true.

Thus the previous example does print "fore!", since the 'if' condition is equivalent to:

if (any(2,4,6) == 4)...

It suffices that any one of 2, 4, or 6 is equal to 4, so the condition is true and the 'if' block executes.

On the other hand, had the control statement been:

    if (all(2,4,6) == 4)...

the condition would fail, since it is not true that all of 2, 4, and 6 are equal to 4.

Operations are also possible between two superpositions:

    if (all(1,2,3)*any(5,6) < 21)
            { print "no alcohol"; }

    if (all(1,2,3)*any(5,6) < 18)
            { print "no entry"; }

    if (any(1,2,3)*all(5,6) < 18)
            { print "under-age" }

In this example, the string "no alcohol" is printed because the superposition produced by the multiplication is the Cartesian product of the respective states of the two operands: 'all(5,6,10,12,15,18)'. Since all of these resultant states are less that 21, the condition is true. In contrast, the string "no entry" is not printed, because not all the product's states are less than 18.

Note that the type of the first operand determines the type of the result of an operation. Hence the third string -- "underage" -- is printed, because multiplying a disjunctive superposition by a conjunctive superposition produces a result that is disjunctive: 'any(5,6,10,12,15,18)'. The condition of the 'if' statement asks whether any of these values is less than 18, which is true.


License: Artistic-1.0
URL: http://search.cpan.org/dist/Quantum-Superpositions/

Categories

Releases

Package Version Update ID Released Package Hub Version Platforms Subpackages
2.03-bp156.3.1 info GA Release 2023-07-22 15 SP6
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Quantum-Superpositions
2.03-bp155.2.8 info GA Release 2023-05-17 15 SP5
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Quantum-Superpositions
2.03-bp154.1.14 info GA Release 2022-05-09 15 SP4
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Quantum-Superpositions
2.02-bp153.266.12 info GA Release 2021-03-06 15 SP3
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Quantum-Superpositions
2.02-bp152.268.12 info GA Release 2020-04-16 15 SP2
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Quantum-Superpositions
2.02-bp151.268.1 info GA Release 2019-07-18 15 SP1
  • AArch64
  • perl-Quantum-Superpositions
2.02-bp151.267.10 info GA Release 2019-05-18 15 SP1
  • ppc64le
  • s390x
  • x86-64
  • perl-Quantum-Superpositions
2.02-bp150.266.3 info GA Release 2018-07-30 15
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Quantum-Superpositions