예제 #1
0
        public State(Matrix <Complex> vector)
        {
            if (vector.RowCount > 1 || !Stuff.IsPowerOfTwo(vector.ColumnCount))
            {
                throw new ArgumentException("State Matrix must be 1 row and 2^n columns");
            }

            this.Vector = vector.NormalizeRows(2.0);
        }
예제 #2
0
        public Gate(string name, int nb_entries, Matrix <Complex> matrix)
        {
            if (matrix.RowCount != matrix.ColumnCount || !Stuff.IsPowerOfTwo(matrix.ColumnCount))
            {
                throw new ArgumentException("Gate Matrix must be 2^n rows and 2^n columns");
            }

            // put identity on zeroed rows
            MathNet.Numerics.LinearAlgebra.Vector <Complex> row_absums = matrix.RowAbsoluteSums();
            for (int i = 0; i < matrix.RowCount; i++)
            {
                if (row_absums[i] == Complex.Zero)
                {
                    matrix[i, i] = Complex.One;
                }
            }

            this.NbEntries = nb_entries;
            this.Matrix    = matrix.NormalizeRows(2.0);

            this.Name = name;
        }