Example #1
0
        public Complex[,] GetMatrix(int bitLen, int bit1Pos, int bit2Pos)
        {
            var matrix = GetMatrix();
            var table  = AlgebraUtility.LookupTable(matrix);

            var mLen = (1 << bitLen);

            matrix = new Complex[mLen, mLen];

            for (int i = 0; i < mLen; i++)
            {
                var x =
                    (BinaryUtility.HasBit(i, bit1Pos) ? 2 : 0) +
                    (BinaryUtility.HasBit(i, bit2Pos) ? 1 : 0);

                foreach (var y in table[x])
                {
                    var j = BinaryUtility.SetBit(
                        i, bit1Pos, BinaryUtility.HasBit(y.Key, 1)
                        );
                    j = BinaryUtility.SetBit(
                        j, bit2Pos, BinaryUtility.HasBit(y.Key, 0)
                        );

                    matrix[i, j] = y.Value;
                    matrix[j, i] = y.Value;
                }
            }

            return(matrix);
        }
Example #2
0
        public void MultiplyBy(UnaryOperation gate, int key)
        {
            var bitLen      = AlgebraUtility.Log2(v.Length);
            var bitPosition = posMap[key];

            v = AlgebraUtility.Multiply(
                gate.GetMatrix(bitLen, bitPosition), v
                );
        }
Example #3
0
        public void MultiplyBy(BinaryOperation gate, int key1, int key2)
        {
            var bitLen  = AlgebraUtility.Log2(v.Length);
            var bit1Pos = posMap[key1];
            var bit2Pos = posMap[key2];

            v = AlgebraUtility.Multiply(
                gate.GetMatrix(bitLen, bit1Pos, bit2Pos), v
                );
        }
Example #4
0
        public static Qstate Combine(Qstate s1, Qstate s2)
        {
            var s = new Qstate();

            s.v      = AlgebraUtility.TensorProduct(s1.v, s2.v);
            s.posMap = s2.posMap;
            var offset = s2.posMap.Count;

            foreach (var pair in s1.posMap)
            {
                s.posMap.Add(pair.Key, pair.Value + offset);
            }
            return(s);
        }