Quantum-Entanglement
view release on metacpan or search on metacpan
Entanglement.pm view on Meta::CPAN
push @{${$newvars[0]->[0]}->[0]}, qw(fake fake); # or here, never
}
}
my $universe = ${$newvars[0]->[0]};
shift @$universe;
foreach (@$stash) {
push @$universe, [@$_];
}
return wantarray ? @newvars : $newvars[0];
}
# this is needed for simplicity of exporting save_states
package Quantum::Entanglement::State;
@Quantum::Entanglement::State::ISA = qw(Quantum::Entanglement);
sub DESTROY {}
1;
__END__;
=head1 NAME
Quantum::Entanglement - QM entanglement of variables in perl
=head1 SYNOPSIS
use Quantum::Entanglement qw(:DEFAULT :complex :QFT);
my $c = entangle(1,0,i,1); # $c = |0> + i|1>
my $d = entangle(1,0,1,1); # $d = |0> + |1>
$e = $c * $d; # $e now |0*0> + i|0*1> + |1*0> + i|1*1>, connected to $c, $d
if ($e == 1) { # observe, probabilistically chose an outcome
# if we are here, ($c,$d) = i|(1,1)>
print "* \$e == 1\n";
}
else { # one of the not 1 versions of $e chosen
# if we are here, ($c,$d) = |(0,0)> + i|(1,0)> + |(0,1)>
print "* \$e != 1\n";
}
=head1 BACKGROUND
"Quantum Mechanics - the dreams that stuff is made of."
Quantum mechanics is one of the stranger things to have emerged from science
over the last hundred years. It has led the way to new understanding
of a diverse range of fundamental physical phenomena and, should recent
developments prove fruitful, could also lead to an entirely new mode
of computation where previously intractable problems find themselves open
to easy solution.
While the detailed results of quantum theory are hard to prove, and
even harder to understand, there are a handful of concepts from the
theory which are more easily understood. Hopefully this module will
shed some light on a few of these and their consequences.
One of the more popular interpretations of quantum mechanics holds that
instead of particles always being in a single, well defined, state
they instead exist as an almost ghostly overlay of many different
states (or values) at the same time. Of course, it is our experience
that when we look at something, we only ever find it in one single state.
This is explained by the many states of the particle collapsing to a
single state and highlights the importance of observation.
In quantum mechanics, the
state of a system can be described by a set of numbers which have
a probability amplitude associated with them.
This probability amplitude is similar to the normal idea of probability
except for two differences. It can be a complex number, which leads
to interference between states, and the probability with which we might
observe a system in a particular state is given by the modulus squared
of this amplitude.
Consider the simple system, often called a I<qubit>, which can take
the value of 0 or 1. If we prepare it in the following superposition
of states (a fancy way of saying that we want it to have many possible
values at once):
particle = 1 * (being equal to 1) + (1-i) * (being equal to 0)
we can then measure (observe) the value of the particle. If we do
this, we find that it will be equal to 1 with a probability of
1**2 / (1**2 + (1-i)(1+i) )
and equal to zero with a probability of
(1+i)(1-i) / (1**2 + (1-i)(1+i) )
the factors on the bottom of each equation being necessary so that the chance
of the particle ending up in any state at all is equal to one.
Observing a particle in this way is said to collapse the wave-function,
or superposition of values, into a single value, which it will retain
from then onwards. A simpler way of writing the equation above is
to say that
particle = 1 |1> + (1-i) |0>
where the probability amplitude for a state is given as a 'multiplier'
of the value of the state, which appears inside the C<< | > >> pattern (this
is called a I<ket>, as sometimes the I<bra> or C<< < | >>, pattern appears
to the left of the probability amplitudes in these equations).
Much of the power of quantum computation comes from collapsing states
and modifying the probability with which a state might collapse to a
particular value as this can be done to each possible state at the same
time, allowing for fantastic degrees of parallelism.
Things also get interesting when you have multiple particles together
in the same system. It turns out that if two particles which exist
in many states at once interact, then after doing so, they will be
linked to one another so that when you measure the value of one
you also affect the possible values that the other can take. This
is called entanglement and is important in many quantum algorithms.
=head1 DESCRIPTION
Essentially, this allows you to put variables into a superposition
( run in 1.786 second using v1.01-cache-2.11-cpan-39bf76dae61 )