KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > physics > quantum > QuantumMath


1 package JSci.physics.quantum;
2
3 import JSci.maths.AbstractMath;
4 import JSci.maths.Complex;
5
6 /**
7 * The Quantum math library.
8 * This class cannot be subclassed or instantiated because all methods are static.
9 * @version 1.5
10 * @author Mark Hale
11 */

12 public final class QuantumMath extends AbstractMath {
13         private QuantumMath() {}
14
15 // COMMUTATOR
16

17         /**
18         * Returns the commutator [A,B].
19         * @param A an operator
20         * @param B an operator
21         */

22         public static Operator commutator(final Operator A, final Operator B) {
23                 return (A.multiply(B)).subtract(B.multiply(A));
24         }
25
26 // ANTICOMMUTATOR
27

28         /**
29         * Returns the anticommutator {A,B}.
30         * @param A an operator
31         * @param B an operator
32         */

33         public static Operator anticommutator(final Operator A, final Operator B) {
34                 return (A.multiply(B)).add(B.multiply(A));
35         }
36
37 // EXPECTATION VALUES
38

39         /**
40         * Returns the expectation value.
41         * @param op an operator
42         * @param ket a ket vector
43         * @exception DimensionException If the operator and vector have different dimensions.
44         */

45         public static Complex expectation(final Operator op, final KetVector ket) {
46                 return ket.toBraVector().multiply(op).multiply(ket);
47         }
48         /**
49         * Returns the expectation value.
50         * @param dm a density matrix
51         * @param op an operator
52         * @exception MatrixDimensionException If the operator and matrix have different dimensions.
53         */

54         public static Complex expectation(final DensityMatrix dm, final Operator op) {
55                 return dm.multiply(op).trace();
56         }
57
58 // PROBABILITIES
59

60         /**
61         * Returns the probability.
62         * @param p a projector
63         * @param ket a ket vector
64         * @exception DimensionException If the projector and vector have different dimensions.
65         */

66         public static Complex probability(final Projector p, final KetVector ket) {
67                 return ket.toBraVector().multiply(p).multiply(ket);
68         }
69         /**
70         * Returns the probability.
71         * @param dm a density matrix
72         * @param p a projector
73         * @exception MatrixDimensionException If the projector and matrix have different dimensions.
74         */

75         public static Complex probability(final DensityMatrix dm, final Projector p) {
76                 return dm.multiply(p).trace();
77         }
78 }
79
80
Popular Tags