package QStuff; use strict; use Exporter; use Math::MatrixReal; use Quantum::Entanglement; our @ISA = qw/Quantum::Entanglement Exporter/; our @EXPORT_OK = qw/entangle/; sub entangle {bless Quantum::Entanglement::entangle(@_)} # args($entangle) returns values passed to entangle() sub args { map {@{$_}} @{${$_[0]->[0]}} } # $entange->probs returns probs only sub probs { my @ar = args(shift); return map {@ar[$_*2]} 0..(int($#ar/2)); } # $entange->states return states only sub states { my @ar = args(shift); return map {@ar[$_*2+1]} 0..(int($#ar/2)); } # $a->cmpquanta($b) sees if 2 quanta the same sub cmpquanta { return 0 unless $_[0]->cmpstates($_[1]); my @probs0 = $_[0]->probs; my @probs1 = $_[1]->probs; for(0..$#probs0){return 0 unless abs($probs0[$_] - $probs1[$_]) < 0.000001} return 1; } # $a->cmpstates($b) sees if $a & $b have the same state space sub cmpstates { my @a = $_[0]->states; my @b = $_[1]->states; return 0 if $#a != $#b; for (0..$#a) {return 0 if $a[$_] != $b[$_]}; return 1; } # project $a onto the subspace of $b sub proj { my ($a, $b) = @_; # checking states compatability to be implemented my @bstates = $b->states; my ($I, $prob, $Pb, $measure, $norm, $measure); $b = Math::MatrixReal->new_from_cols([[$b->probs]]); $a = Math::MatrixReal->new_from_cols([[$a->probs]]); $I = Math::MatrixReal->new_diag( [1, 1] ); $prob = (~$a * $b * ~$b * $a)->element(1,1); $Pb = rand(1) < $prob ? $b * ~$b : ($I - $b * ~$b ); # quantum thing $measure = $Pb * $a; $norm = sqrt((~($measure) * $measure)->element(1,1)); $measure = $Pb * $a * (1/$norm); bless QStuff::entangle( map {$measure->element($_+1, 1) => $bstates[$_]} 0..$#bstates ); } 1;