コード例 #1
0
 /*
  * Generalized Hadamard gate
  */
 public static QuantumGate HadamardGateOfLength(int registerLength)
 {
     if (registerLength == 1)
     {
         return(QuantumGate.HadamardGate);
     }
     else
     {
         return(new QuantumGate(QuantumGate.HadamardGate, QuantumGate.HadamardGateOfLength(registerLength - 1)));
     }
 }
コード例 #2
0
        /*
         * Determines whether the specified quantum gate is equal to the current quantum gate
         */
        public override bool Equals(object obj)
        {
            QuantumGate quantumGate = obj as QuantumGate;

            if (quantumGate == null || this.Matrix.ColumnCount != quantumGate.Matrix.ColumnCount || this.Matrix.RowCount != quantumGate.Matrix.RowCount)
            {
                return(false);
            }

            return(this.Matrix.Equals(quantumGate.Matrix));
        }
コード例 #3
0
        /*
         * Determines whether the specified quantum gate is equal to the current quantum gate, ignoring floating-point precision issues
         */
        public bool AlmostEquals(object obj)
        {
            QuantumGate quantumGate = obj as QuantumGate;

            if (quantumGate == null || this.Matrix.ColumnCount != quantumGate.Matrix.ColumnCount || this.Matrix.RowCount != quantumGate.Matrix.RowCount)
            {
                return(false);
            }

            return(Precision.AlmostEqual <Complex>(this.Matrix, quantumGate.Matrix, 15));
        }
コード例 #4
0
        /*
         * Controlled gate
         */
        public static QuantumGate ControlledGate(QuantumGate gate)
        {
            if (gate.Matrix.ColumnCount != 2 || gate.Matrix.RowCount != 2)
            {
                throw new ArgumentException("A controlled gate can only be created from a unary gate.");
            }

            return(new QuantumGate(new Complex[, ] {
                { 1, 0, 0, 0 },
                { 0, 1, 0, 0 },
                { 0, 0, gate.Matrix.At(0, 0), gate.Matrix.At(0, 1) },
                { 0, 0, gate.Matrix.At(1, 0), gate.Matrix.At(1, 1) },
            }));
        }