예제 #1
0
        public TensorProduct GetProduct(double [,] matrix, TensorProduct q)
        {
            TensorProduct getQ = new TensorProduct();

            getQ.alpha = matrix[0, 0] * q.alpha + matrix[0, 1] * q.beta + matrix[0, 2] * q.gama +
                         matrix[0, 3] * q.delta;
            getQ.beta = matrix[1, 0] * q.alpha + matrix[1, 1] * q.beta + matrix[1, 2] * q.gama +
                        matrix[1, 3] * q.delta;
            getQ.gama = matrix[2, 0] * q.alpha + matrix[2, 1] * q.beta + matrix[2, 2] * q.gama +
                        matrix[2, 3] * q.delta;
            getQ.delta = matrix[3, 0] * q.alpha + matrix[3, 1] * q.beta + matrix[3, 2] * q.gama +
                         matrix[3, 3] * q.delta;
            return(getQ);
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please input Qubit");

            Console.WriteLine("Please input a");
            var numbers    = Console.ReadLine();
            var numberList = numbers.Split(' ');
            var number1    = Convert.ToDouble(numberList[0]);
            var number2    = Convert.ToDouble(numberList[1]);
            //Console.WriteLine(number1 + " " + number2);
            Complex c1 = new Complex(number1, number2);

            Console.WriteLine("Please input b");
            var numbers2    = Console.ReadLine();
            var numberList2 = numbers2.Split(' ');
            var number12    = Convert.ToDouble(numberList2[0]);
            var number22    = Convert.ToDouble(numberList2[1]);
            //Console.WriteLine(number11 + " " + number22);
            Complex c2 = new Complex(number12, number22);

            Qubit   q  = new Qubit(c1, c2);
            Complex p1 = new Complex(0, 0);
            Complex p2 = new Complex(1, 0);

            Qubit         p  = new Qubit(p1, p2);
            TensorProduct tq = new TensorProduct(q, p);

            Matrix        m   = new Matrix();
            TensorProduct tq1 = m.GetProduct(m.HHmatrix(), tq);
            TensorProduct tq2 = m.GetProduct(m.inputMatrix(), tq1);
            TensorProduct tq3 = m.GetProduct(m.HImatrix(), tq2);

            //Console.WriteLine(tq3.measure());
            if (tq3.measure() == 0)
            {
                Console.WriteLine("Function is constant");
            }
            else
            {
                Console.WriteLine("Function is not constant");
            }
            // if we run the computer several times with the same input data, the output might be different each time.
            // In Deutsch algorthm, the input data is chosen very specifically so that output will stay the same
        }