当前位置: 首页>>代码示例>>C#>>正文


C# this.AddParametricGate方法代码示例

本文整理汇总了C#中this.AddParametricGate方法的典型用法代码示例。如果您正苦于以下问题:C# this.AddParametricGate方法的具体用法?C# this.AddParametricGate怎么用?C# this.AddParametricGate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在this的用法示例。


在下文中一共展示了this.AddParametricGate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddModuloQFTPhi

        public static void AddModuloQFTPhi(this QuantumComputer comp, ulong a, ulong N, RegisterRef ctrl, Register b, params RegisterRef[] controls)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, a, N, ctrl, b, controls };
                comp.AddParametricGate("AddModuloQFTPhi", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            comp.AddQFTPhi(a, b, controls);
            comp.InverseAddQFTPhi(N, b);

            comp.InverseQFT(b);
            comp.CNot(ctrl, b[b.Width - 1]);
            comp.QFT(b);

            comp.AddQFTPhi(N, b, ctrl);
            comp.InverseAddQFTPhi(a, b, controls);

            comp.InverseQFT(b);
            comp.SigmaX(b[b.Width - 1]);
            comp.CNot(ctrl, b[b.Width - 1]);
            comp.SigmaX(b[b.Width - 1]);
            comp.QFT(b);

            comp.AddQFTPhi(a, b, controls);
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:31,代码来源:AddModuloQFTExtension.cs

示例2: Add

        // Add(a, b, 0) -> (a, a+b, 0)
        // Registers a, b and c must not overlap
        // Registers a and b have the same width
        // Register c is used for storing carries and must be minimum one bit wider than register a (or b)
        // Initial value of c must be 0
        public static void Add(this QuantumComputer comp,
            Register a, Register b, Register c)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, a, b, c };
                comp.AddParametricGate("Add", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            int width = a.Width;
            int i = 0;
            for (; i < width - 1; i++)
            {
                comp.Carry(c[i], a[i], b[i], c[i + 1]);
            }
            comp.Carry(c[i], a[i], b[i], b[i + 1]);

            comp.CNot(b[i], a[i]);
            comp.Sum(c[i], a[i], b[i]);
            i--;
            for (; i >= 0; i--)
            {
                comp.InverseCarry(c[i], a[i], b[i], c[i + 1]);
                comp.Sum(c[i], a[i], b[i]);
            }
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:36,代码来源:AddExtension.cs

示例3: AddQFTPhi

        public static void AddQFTPhi(this QuantumComputer comp, Register a, Register b, params RegisterRef[] controls)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, a, b, controls };
                comp.AddParametricGate("AddQFTPhi", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            Validate(a, b);

            for (int j = b.Width - 1; j >= 0; j--)
            {
                for (int i = j; i >= 0; i--)
                {
                    List<RegisterRef> list = controls.ToList<RegisterRef>();
                    list.Add(a[i]);
                    RegisterRef[] controls2 = list.ToArray();
                    comp.CPhaseShift(Math.Abs(j-i), b[j], controls2);
                }
            }
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:26,代码来源:AddQFTExtension.cs

示例4: ControlledUaGate

        public static void ControlledUaGate(this QuantumComputer comp, ulong a, ulong N, RegisterRef ctrl, Register x, Register reg0, RegisterRef control)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, a, N, ctrl, x, reg0, control };
                comp.AddParametricGate("ControlledUaGate", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            Validate(x, N);

            int? invA = Quantum.Utils.InversionModulo((int)a, (int)N);

            if (invA == null)
            {
                throw new ArgumentException("No inversion for specified a = " + a);
            }

            comp.MultModuloQFT(a, N, ctrl, x, reg0, control);
            comp.Swap(x, reg0, control);
            comp.InverseMultModuloQFT((ulong)invA, N, ctrl, x, reg0, control);
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:26,代码来源:ControlledUGateExtension.cs

示例5: InverseLoadNumber

 public static void InverseLoadNumber(this QuantumComputer comp, Register target, ulong number, params RegisterRef[] controlBits)
 {
     if (comp.Group)
     {
         object[] parameters = new object[] { comp, target, number, controlBits };
         comp.AddParametricGate("InverseLoadNumber", parameters);
         return;
     }
     else
     {
         comp.Group = true;
     }
     comp.LoadNumber(target, number, controlBits);
 }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:14,代码来源:LoadNumberExtension.cs

示例6: InverseReverse

        public static void InverseReverse(this QuantumComputer comp, Register a)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, a };
                comp.AddParametricGate("InverseReverse", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            comp.Reverse(a);
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:15,代码来源:SwapExtension.cs

示例7: InverseSwap

        public static void InverseSwap(this QuantumComputer comp, Register r1, Register r2, RegisterRef control)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, r1, r2, control };
                comp.AddParametricGate("InverseSwap", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            comp.Swap(r1, r2, control);
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:15,代码来源:SwapExtension.cs

示例8: InverseWalsh

        public static void InverseWalsh(this QuantumComputer comp, Register register)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, register };
                comp.AddParametricGate("InverseWalsh", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            comp.Walsh(register);
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:15,代码来源:WalshExtension.cs

示例9: ExpModulo

        // register X - initially loaded with x
        // register X_1 - initially loaded with 1
        // W = width(a) = width(N)
        // width(b) = width(c) = width(x1) = W + 1
        // width(X) is 2 * W
        // register N - initially loaded with N
        // other registers - initially 0
        // after computation register X_1 changes and contains: [(a^x) mod N]
        // Insecure version: registers widths etc. are not checked
        public static void ExpModulo(
            this QuantumComputer comp,
            Register a,
            Register b,
            Register c,
            Register N,
            Register x1,
            Register x,
            int valueA,
            int valueN)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, a, b, c, N, x1, x, valueA, valueN };
                comp.AddParametricGate("ExpModulo", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            bool firstRegisterB = false;
            int pow_a_2 = valueA;

            for (int i = 0; i < x.Width; i++)
            {
                // finding the inversion modulo of pow_a_2
                int inv_mod = InversionModulo(pow_a_2, valueN);

                if (firstRegisterB)
                {
                    comp.CMultModulo(a, x1, c, N, b, x[i],
                        (ulong)pow_a_2, (ulong)valueN);
                    comp.InverseCMultModulo(a, b, c, N, x1, x[i],
                        (ulong)inv_mod, (ulong)valueN);
                }
                else
                {
                    comp.CMultModulo(a, b, c, N, x1, x[i],
                        (ulong)pow_a_2, (ulong)valueN);
                    comp.InverseCMultModulo(a, x1, c, N, b, x[i],
                        (ulong)inv_mod, (ulong)valueN);
                }
                pow_a_2 = (pow_a_2 * pow_a_2) % valueN;
                firstRegisterB = !firstRegisterB;
            }
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:57,代码来源:ExpModuloExtension.cs

示例10: AddModuloQFT

        public static void AddModuloQFT(this QuantumComputer comp, ulong a, ulong N, Register b, params RegisterRef[] controls)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, a, N, b, controls };
                comp.AddParametricGate("AddModuloQFT", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            Register ctrl = comp.NewRegister(0, 1);
            comp.AddModuloQFT(a, N, ctrl, b, controls);
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:16,代码来源:AddModuloQFTExtension.cs

示例11: InverseMultModuloQFT

        public static void InverseMultModuloQFT(this QuantumComputer comp, ulong a, ulong N, Register x, Register b, RegisterRef control)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, a, N, x, b, control };
                comp.AddParametricGate("InverseMultModuloQFT", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            Register ctrl = comp.NewRegister(0, 1);
            comp.InverseMultModuloQFT(a, N, ctrl, x, b, control);
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:16,代码来源:MultModuloQFTExtension.cs

示例12: CMultModulo

        // register x - initially loaded with x
        // register N - initially loaded with N
        // control - control bit
        // other registers - initially 0
        // after computation register B changes and contains: [(a*x) mod N]
        // Insecure version: registers widths etc. are not checked
        public static void CMultModulo(
            this QuantumComputer comp,
            Register a,
            Register b,
            Register c,
            Register N,
            Register x,
            RegisterRef control,
            ulong valueA,
            ulong valueN)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, a, b, c, N, x, control, valueA, valueN };
                comp.AddParametricGate("CMultModulo", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            ulong power2 = 1;
            for (int i = 0; i < x.Width; i++, power2 *= 2)
            {
                // loading A register with (2^i * a) mod N
                ulong toLoad = (valueA * power2) % valueN;
                comp.LoadNumber(a, toLoad, control, x[i]);

                // adding [(2^i * a) + B] modulo N
                comp.AddModulo(a, b, c, N, valueN);

                // unloading [(2^i * a) mod N] from A register
                comp.LoadNumber(a, toLoad, control, x[i]);
            }

            // if control == 0
            // then B register contains still 0
            // so we copy X register into B register
            comp.SigmaX(control);
            for (int i = 0; i < x.Width; i++)
            {
                comp.Toffoli(b[i], control, x[i]);
            }
            comp.SigmaX(control);
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:52,代码来源:MultModuloExtension.cs

示例13: Walsh

        //Apply a walsh-hadamard transform on whole register
        public static void Walsh(this QuantumComputer comp, Register register)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, register };
                comp.AddParametricGate("Walsh", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            for (int i = 0; i < register.Width; i++)
            {
                register.Hadamard(i);
            }
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:19,代码来源:WalshExtension.cs

示例14: AddQFT

        public static void AddQFT(this QuantumComputer comp, ulong a, Register b, params RegisterRef[] controls)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, a, b, controls };
                comp.AddParametricGate("AddQFT", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            Validate(a, b);
            comp.QFT(b);
            comp.AddQFTPhi(a, b, controls);
            comp.InverseQFT(b);
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:18,代码来源:AddQFTExtension.cs

示例15: AddModulo

        // register A - initially loaded with a
        // register B - initially loaded with b
        // register C - initially 0, exactly one bit wider than A, stores overflow bit
        // register N - initially loaded with N
        // after computation in register B: (a+b) mod N
        // other registers dont change their states
        // register B must be exactly one bit wider than A to store carry bit
        // register B must be exactly one bit wider than N to store carry bit
        // registers A, N must be the same length
        // Insecure version: registers widths etc. are not checked
        public static void AddModulo(
            this QuantumComputer comp,
            Register a,
            Register b,
            Register c,
            Register N,
            ulong valueN)
        {
            if (comp.Group)
            {
                object[] parameters = new object[] { comp, a, b, c, N, valueN };
                comp.AddParametricGate("AddModulo", parameters);
                return;
            }
            else
            {
                comp.Group = true;
            }

            RegisterRef carry = b[b.Width - 1];
            RegisterRef overflow = c[c.Width - 1];

            comp.Add(a, b, c);
            comp.InverseAdd(N, b, c);
            comp.SigmaX(carry);
            comp.CNot(overflow, carry);
            comp.SigmaX(carry);

            //resetting N
            comp.LoadNumber(N, valueN, overflow);

            comp.Add(N, b, c);

            // now we have [(a+b) mod N] in B register
            // next steps lead to recover the initial state of registers N and overflow bit

            //setting N back
            comp.LoadNumber(N, valueN, overflow);

            comp.InverseAdd(a, b, c);
            comp.CNot(overflow, carry);
            comp.Add(a, b, c);
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:53,代码来源:AddModuloExtension.cs


注:本文中的this.AddParametricGate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。