static public void TestMethod3() { var list = new List <Matrix>(); Complex[,] array1 = { { 0.5, 0.5 }, { 0.5, 0.5 } }; var value = (Matrix)Matrix.Build.DenseOfArray(array1); list.Add(value); Complex[,] array2 = { { 0.5, -0.5 }, { -0.5, 0.5 } }; value = (Matrix)Matrix.Build.DenseOfArray(array2); list.Add(value); var measureMatrix2 = new MeasureMatrix2(list.ToArray()); Complex[,] array3 = { { 1 / Sqrt(2), 1 / Sqrt(2) }, { 1 / Sqrt(2), -1 / Sqrt(2) } }; var unitaryTransMatrix = (Matrix)Matrix.Build.DenseOfArray(array3); for (;;) { var ret = new int[2]; for (var i = 0; i < 100; i++) { var qBit = new QBit(false); qBit.UnitaryTrans2(unitaryTransMatrix); ret[qBit.Measu2ResultIndex(measureMatrix2)]++; } for (var i = 0; i < ret.Length; i++) { Console.WriteLine($"{i} is {ret[i]}"); } } }
static public void TestMethod() { Console.WriteLine("QBit value"); Console.WriteLine(new QBit(false).Value.ToComplexString()); var matrixArray = new Matrix[2]; Complex[,] array0 = { { 0.5, 0.5 }, { 0.5, 0.5 } }; matrixArray[0] = (Matrix)Matrix.Build.DenseOfArray(array0); Complex[,] array1 = { { 0.5, -0.5 }, { -0.5, 0.5 } }; matrixArray[1] = (Matrix)Matrix.Build.DenseOfArray(array1); var measureMatrix2 = new MeasureMatrix2(matrixArray); Console.WriteLine("Measurement matrix 0"); Console.WriteLine(measureMatrix2.Value[0].ToComplexString()); Console.WriteLine("Measurement matrix 1"); Console.WriteLine(measureMatrix2.Value[1].ToComplexString()); int count; var countNumber = new SortedDictionary <int, int>(); // var qbit = new QBit(false); for (var i = 0; i < 1000; i++) { var qbit = new QBit(false); count = 0; qwhile(qbit, measureMatrix2, 1, () => { qbit.UnitaryTrans2(HGate.Value); count++; if (count > 1000) { return(CWHILEFLOW.BREAK); } return(CWHILEFLOW.CONTINUE); } ); if (countNumber.ContainsKey(count)) { countNumber[count]++; } else { countNumber[count] = 1; } } foreach (var pair in countNumber) { Console.WriteLine($"{pair.Key} is {pair.Value}"); } }
static public void TestMethod() { var qBit1 = new QBit(false); Complex[,] array1 = { { new Complex(0, 0), new Complex(1, 0) }, { new Complex(1, 0), new Complex(0, 0) } }; var matrix1 = (Matrix)Matrix.Build.DenseOfArray(array1); Console.WriteLine(qBit1.Value.ToComplexString()); qBit1.UnitaryTrans2(matrix1); Console.WriteLine(qBit1.Value.ToComplexString()); }
static public void TestMethod() { var qbit = new QBit(false); Console.WriteLine("QBit value"); Console.WriteLine(qbit.Value.ToComplexString()); var matrixArray = new Matrix[2]; Complex[,] array0 = { { 0.5, 0.5 }, { 0.5, 0.5 } }; matrixArray[0] = (Matrix)Matrix.Build.DenseOfArray(array0); Complex[,] array1 = { { 0.5, -0.5 }, { -0.5, 0.5 } }; matrixArray[1] = (Matrix)Matrix.Build.DenseOfArray(array1); var measureMatrix2 = new MeasureMatrix2(matrixArray); Console.WriteLine("Measurement matrix 0"); Console.WriteLine(measureMatrix2.Value[0].ToComplexString()); Console.WriteLine("Measurement matrix 1"); Console.WriteLine(measureMatrix2.Value[1].ToComplexString()); int count_0 = 0, count_1 = 0; for (var i = 0; i < 1000; i++) { qif(qbit, measureMatrix2, () => { count_0++; }, () => { count_1++; } ); qbit.UnitaryTrans2(HGate.Value); } Console.WriteLine($"count_0 = {count_0}"); Console.WriteLine($"count_1 = {count_1}"); }