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.510 * @author Mark Hale11 */12 public final class QuantumMath extends AbstractMath {13         private QuantumMath() {}14 15 // COMMUTATOR16 17         /**18         * Returns the commutator [A,B].19         * @param A an operator20         * @param B an operator21         */22         public static Operator commutator(final Operator A, final Operator B) {23                 return (A.multiply(B)).subtract(B.multiply(A));24         }25 26 // ANTICOMMUTATOR27 28         /**29         * Returns the anticommutator {A,B}.30         * @param A an operator31         * @param B an operator32         */33         public static Operator anticommutator(final Operator A, final Operator B) {34                 return (A.multiply(B)).add(B.multiply(A));35         }36 37 // EXPECTATION VALUES38 39         /**40         * Returns the expectation value.41         * @param op an operator42         * @param ket a ket vector43         * @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 matrix51         * @param op an operator52         * @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 // PROBABILITIES59 60         /**61         * Returns the probability.62         * @param p a projector63         * @param ket a ket vector64         * @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 matrix72         * @param p a projector73         * @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