see other projects

Q::S::L module

Weighted QM-like superpositions with lazy evaluation

Quantum mechanics simplified

Quantum::Superpositions::Lazy module enables application of quantum phenomena to your Perl code. It does not actually handle real quantum physics calculations, but allows Perl variables to act as if they were in a state of superposition. It is intended to be a successor to Damian Conway's Quantum::Superpositions, with different syntax and more capabilities.

Example code

use v5.28;
use Quantum::Superpositions::Lazy;
use List::Util qw(reduce);

my @coin_flips;
push @coin_flips, superpos(qw(heads tails))
    for 1 .. 10;

my $all_at_once = reduce { $a . ', ' . $b } @coin_flips;
say 'The random flip of ten coins at once is: ' . $all_at_once->collapse;

say 'Here come the possible states...';
use Data::Dumper;
say Dumper($all_at_once->states->@[1 .. 3]);

Example output

The random flip of ten coins at once is: heads, tails, heads, tails, heads, heads, heads, tails, heads, heads
Here come the possible states...
$VAR1 = bless( {
                 'value' => 'heads, heads, heads, tails, tails, heads, heads, tails, tails, heads',
                 'weight' => '0.0009765625'
               }, 'Quantum::Superpositions::Lazy::State' );
$VAR2 = bless( {
                 'weight' => '0.0009765625',
                 'value' => 'heads, tails, heads, heads, tails, tails, tails, heads, tails, tails'
               }, 'Quantum::Superpositions::Lazy::State' );
$VAR3 = bless( {
                 'weight' => '0.0009765625',
                 'value' => 'tails, tails, tails, tails, heads, tails, tails, heads, heads, heads'
               }, 'Quantum::Superpositions::Lazy::State' );