Quantum-Superpositions

 view release on metacpan or  search on metacpan

lib/Quantum/Superpositions.pm  view on Meta::CPAN

use base 'Quantum::Superpositions';
use Carp;

sub qstr
{
	my @eigenstate = $_[0]->eigenstates;

	@eigenstate ? "@eigenstate" : "all(".join(",",@{$_[0]}).")" 
}

sub quop { return Quantum::Superpositions::all(map { $_[1]->($_) } @{$_[0]}) }

sub qulop
{
	$_[1]->($_) || return Quantum::Superpositions::all() for @{$_[0]};

	Quantum::Superpositions::all(@{$_[0]})
}


package Quantum::Superpositions::Conj::True;
use base 'Quantum::Superpositions::Conj';

sub qbool { 1 }


1;

__END__

=head1 NAME

Quantum::Superpositions - QM-like superpositions in Perl

=head1 VERSION

This document describes version 1.03 of Quantum::Superpositions,
released August 11, 2000.

=head1 SYNOPSIS

	use Quantum::Superpositions;

	if ($x == any($a, $b, $c)) { ...  }

	while ($nextval < all(@thresholds)) { ... }

	$max = any(@value) < all(@values);


	use Quantum::Superpositions BINARY => [ CORE::index ];

	print index( any("opts","tops","spot"), "o" );
	print index( "stop", any("p","s") ); 


=head1 BACKGROUND

Under the standard interpretation of quantum mechanics, until they are observed, particles exist only as a discontinuous probability 
function. Under the Cophenhagen Interpretation, this situation is often visualized by imagining the state of an unobserved particle to be 
a ghostly overlay of all its possible observable 
states simultaneously. For example, a particle 
that might be observed in state A, B, or C may 
be considered to be in a pseudo-state where 
it is simultaneously in states A, B, and C.
Such a particle is said to be in a superposition of states.

Research into applying particle superposition 
in construction of computer hardware is already well advanced. The aim of such 
research is to develop reliable quantum 
memories, in which an individual bit is stored 
as some measurable property of a quantised 
particle (a qubit). Because the particle can be 
physically coerced into a superposition of 
states, it can store bits that are simultaneously 
1 and 0. 

Specific processes based on the interactions of 
one or more qubits (such as interference, entanglement, or additional superposition) are 
then be used to construct quantum logic 
gates. Such gates can in turn be employed to 
perform logical operations on qubits, allowing logical and mathematical operations to be 
executed in parallel.

Unfortunately, the math required to design and use
quantum algorithms on quantum computers is painfully
hard. The Quantum::Superpositions module offers
another approach, based on the superposition of
entire scalar values (rather than individual qubits).

=head1 DESCRIPTION

The Quantum::Superpositions module adds two
new operators to Perl: C<any> and C<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 C<any> and C<all> operators produce two distinct kinds of superposition. The C<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 C<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;



( run in 2.388 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )