How to compute the inverse of an operation in Q#?How to create an arbitrary state in QISKit for a...

Is Newton's third law really correct?

How Hebrew Vowels Work

reverse a call to mmap()

How can the US president give an order to a civilian?

Is using legacy mode instead of UEFI mode a bad thing to do?

Why one uses 了 and the other one doesn’t?

How do I find which software is doing an SSH connection?

How to modify a string without altering its text properties

"Correct me if I'm wrong"

What mathematical theory is required for high frequency trading?

How can I restore a master database from its bak file?

Print the new site header

Is there a polite way to ask about one's ethnicity?

How to write a nice frame challenge?

Time at 1 g acceleration to travel 100 000 light years

Why are there no file insertion syscalls

Is there any possible way to get these hearts as Adult Link?

I found a password with hashcat but it doesn't work

Do details of my undergraduate title matter?

Why things float in space, though there is always gravity of our star is present

What is that ceiling compartment of a Boeing 737?

How "fast" do astronomical events occur?

Counterfeit checks were created for my account. How does this type of fraud work?

Why there is a red color in right side?



How to compute the inverse of an operation in Q#?


How to create an arbitrary state in QISKit for a local_qasm_simulator?How do we code the matrix for a controlled operation knowing the control qubit, the target qubit and the $2times 2$ unitary?How to construct the “Inversion About the Mean” operator?How would one implement a quantum equivalent of a while loop in IBM QISkit?Quantum counting in Q#How many logical qubits are needed to run Shor's algorithm efficiently on large integers ($n > 2^{1024}$)?How do I produce circuit diagrams from a Q# program?Representing a real valued vector with qubitsHow do I get a list of control qubits from Q# operations when tracing the simulation in C#?How do I do printf debugging in Q# in a convenient way?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1












$begingroup$


I want to implement amplitude amplification using Q#. I have the operation $A$
that prepares my initial state and I need to compute $ A^{-1} $ to implement the algorithm.



Is there an easy way to do that in Q# (a keyword or operation)?










share|improve this question









New contributor



Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$



















    1












    $begingroup$


    I want to implement amplitude amplification using Q#. I have the operation $A$
    that prepares my initial state and I need to compute $ A^{-1} $ to implement the algorithm.



    Is there an easy way to do that in Q# (a keyword or operation)?










    share|improve this question









    New contributor



    Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






    $endgroup$















      1












      1








      1





      $begingroup$


      I want to implement amplitude amplification using Q#. I have the operation $A$
      that prepares my initial state and I need to compute $ A^{-1} $ to implement the algorithm.



      Is there an easy way to do that in Q# (a keyword or operation)?










      share|improve this question









      New contributor



      Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      $endgroup$




      I want to implement amplitude amplification using Q#. I have the operation $A$
      that prepares my initial state and I need to compute $ A^{-1} $ to implement the algorithm.



      Is there an easy way to do that in Q# (a keyword or operation)?







      programming q#






      share|improve this question









      New contributor



      Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question









      New contributor



      Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question








      edited 9 hours ago









      Sanchayan Dutta

      7,76441662




      7,76441662






      New contributor



      Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 9 hours ago









      Sorin BolosSorin Bolos

      183




      183




      New contributor



      Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          2 Answers
          2






          active

          oldest

          votes


















          3












          $begingroup$

          As given in the documentation, if your operation is unitary, you can add the statement adjoint auto; within the operation after the body block. This will generate the adjoint (which is the inverse for unitary).



          Then, to use the inverse call Adjoint A(parameters)






          share|improve this answer









          $endgroup$









          • 1




            $begingroup$
            Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
            $endgroup$
            – Sorin Bolos
            8 hours ago



















          3












          $begingroup$

          In the case that your operation can be represented by a unitary operator $U$ (this is typically the case if your operation doesn't use any measurements), you can indicate that by adding is Adj to your operation's signature, letting the Q# compiler know that your operation is adjointable:



          open Microsoft.Quantum.Math as Math;

          /// # Summary
          /// Prepares a qubit in a state representing a classical probability
          /// distribution {p, 1 - p}.
          /// # Description
          /// Given a qubit in the |0⟩, prepares √p |0⟩ + √(1 - p) |1⟩
          /// for a given probability p.
          operation PrepareDistribution(probability : Double, target : Qubit) : Unit
          is Adj {
          let rotationAngle = 2.0 * Math.ArcCos(Math.Sqrt(1.0 - probability));
          Ry(rotationAngle, target);
          }


          You can then call Adjoint PrepareDistribution to "undo" the PrepareDistribution operation. The Adjoint keyword is an example of a Q# functor, and tells Q# that you want the inverse operation. In this case, the Q# compiler will apply Ry(-rotationAngle, target).



          For more information:




          • Functors


          • Learn Quantum Computing with Python and Q# (chapter 6 covers the example above, future chapters will talk more about functors)






          share|improve this answer









          $endgroup$














            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "694"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            noCode: true, onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            Sorin Bolos is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fquantumcomputing.stackexchange.com%2fquestions%2f6477%2fhow-to-compute-the-inverse-of-an-operation-in-q%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3












            $begingroup$

            As given in the documentation, if your operation is unitary, you can add the statement adjoint auto; within the operation after the body block. This will generate the adjoint (which is the inverse for unitary).



            Then, to use the inverse call Adjoint A(parameters)






            share|improve this answer









            $endgroup$









            • 1




              $begingroup$
              Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
              $endgroup$
              – Sorin Bolos
              8 hours ago
















            3












            $begingroup$

            As given in the documentation, if your operation is unitary, you can add the statement adjoint auto; within the operation after the body block. This will generate the adjoint (which is the inverse for unitary).



            Then, to use the inverse call Adjoint A(parameters)






            share|improve this answer









            $endgroup$









            • 1




              $begingroup$
              Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
              $endgroup$
              – Sorin Bolos
              8 hours ago














            3












            3








            3





            $begingroup$

            As given in the documentation, if your operation is unitary, you can add the statement adjoint auto; within the operation after the body block. This will generate the adjoint (which is the inverse for unitary).



            Then, to use the inverse call Adjoint A(parameters)






            share|improve this answer









            $endgroup$



            As given in the documentation, if your operation is unitary, you can add the statement adjoint auto; within the operation after the body block. This will generate the adjoint (which is the inverse for unitary).



            Then, to use the inverse call Adjoint A(parameters)







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 8 hours ago









            Mahathi VempatiMahathi Vempati

            7649




            7649








            • 1




              $begingroup$
              Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
              $endgroup$
              – Sorin Bolos
              8 hours ago














            • 1




              $begingroup$
              Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
              $endgroup$
              – Sorin Bolos
              8 hours ago








            1




            1




            $begingroup$
            Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
            $endgroup$
            – Sorin Bolos
            8 hours ago




            $begingroup$
            Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
            $endgroup$
            – Sorin Bolos
            8 hours ago













            3












            $begingroup$

            In the case that your operation can be represented by a unitary operator $U$ (this is typically the case if your operation doesn't use any measurements), you can indicate that by adding is Adj to your operation's signature, letting the Q# compiler know that your operation is adjointable:



            open Microsoft.Quantum.Math as Math;

            /// # Summary
            /// Prepares a qubit in a state representing a classical probability
            /// distribution {p, 1 - p}.
            /// # Description
            /// Given a qubit in the |0⟩, prepares √p |0⟩ + √(1 - p) |1⟩
            /// for a given probability p.
            operation PrepareDistribution(probability : Double, target : Qubit) : Unit
            is Adj {
            let rotationAngle = 2.0 * Math.ArcCos(Math.Sqrt(1.0 - probability));
            Ry(rotationAngle, target);
            }


            You can then call Adjoint PrepareDistribution to "undo" the PrepareDistribution operation. The Adjoint keyword is an example of a Q# functor, and tells Q# that you want the inverse operation. In this case, the Q# compiler will apply Ry(-rotationAngle, target).



            For more information:




            • Functors


            • Learn Quantum Computing with Python and Q# (chapter 6 covers the example above, future chapters will talk more about functors)






            share|improve this answer









            $endgroup$


















              3












              $begingroup$

              In the case that your operation can be represented by a unitary operator $U$ (this is typically the case if your operation doesn't use any measurements), you can indicate that by adding is Adj to your operation's signature, letting the Q# compiler know that your operation is adjointable:



              open Microsoft.Quantum.Math as Math;

              /// # Summary
              /// Prepares a qubit in a state representing a classical probability
              /// distribution {p, 1 - p}.
              /// # Description
              /// Given a qubit in the |0⟩, prepares √p |0⟩ + √(1 - p) |1⟩
              /// for a given probability p.
              operation PrepareDistribution(probability : Double, target : Qubit) : Unit
              is Adj {
              let rotationAngle = 2.0 * Math.ArcCos(Math.Sqrt(1.0 - probability));
              Ry(rotationAngle, target);
              }


              You can then call Adjoint PrepareDistribution to "undo" the PrepareDistribution operation. The Adjoint keyword is an example of a Q# functor, and tells Q# that you want the inverse operation. In this case, the Q# compiler will apply Ry(-rotationAngle, target).



              For more information:




              • Functors


              • Learn Quantum Computing with Python and Q# (chapter 6 covers the example above, future chapters will talk more about functors)






              share|improve this answer









              $endgroup$
















                3












                3








                3





                $begingroup$

                In the case that your operation can be represented by a unitary operator $U$ (this is typically the case if your operation doesn't use any measurements), you can indicate that by adding is Adj to your operation's signature, letting the Q# compiler know that your operation is adjointable:



                open Microsoft.Quantum.Math as Math;

                /// # Summary
                /// Prepares a qubit in a state representing a classical probability
                /// distribution {p, 1 - p}.
                /// # Description
                /// Given a qubit in the |0⟩, prepares √p |0⟩ + √(1 - p) |1⟩
                /// for a given probability p.
                operation PrepareDistribution(probability : Double, target : Qubit) : Unit
                is Adj {
                let rotationAngle = 2.0 * Math.ArcCos(Math.Sqrt(1.0 - probability));
                Ry(rotationAngle, target);
                }


                You can then call Adjoint PrepareDistribution to "undo" the PrepareDistribution operation. The Adjoint keyword is an example of a Q# functor, and tells Q# that you want the inverse operation. In this case, the Q# compiler will apply Ry(-rotationAngle, target).



                For more information:




                • Functors


                • Learn Quantum Computing with Python and Q# (chapter 6 covers the example above, future chapters will talk more about functors)






                share|improve this answer









                $endgroup$



                In the case that your operation can be represented by a unitary operator $U$ (this is typically the case if your operation doesn't use any measurements), you can indicate that by adding is Adj to your operation's signature, letting the Q# compiler know that your operation is adjointable:



                open Microsoft.Quantum.Math as Math;

                /// # Summary
                /// Prepares a qubit in a state representing a classical probability
                /// distribution {p, 1 - p}.
                /// # Description
                /// Given a qubit in the |0⟩, prepares √p |0⟩ + √(1 - p) |1⟩
                /// for a given probability p.
                operation PrepareDistribution(probability : Double, target : Qubit) : Unit
                is Adj {
                let rotationAngle = 2.0 * Math.ArcCos(Math.Sqrt(1.0 - probability));
                Ry(rotationAngle, target);
                }


                You can then call Adjoint PrepareDistribution to "undo" the PrepareDistribution operation. The Adjoint keyword is an example of a Q# functor, and tells Q# that you want the inverse operation. In this case, the Q# compiler will apply Ry(-rotationAngle, target).



                For more information:




                • Functors


                • Learn Quantum Computing with Python and Q# (chapter 6 covers the example above, future chapters will talk more about functors)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 8 hours ago









                Chris GranadeChris Granade

                19316




                19316






















                    Sorin Bolos is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    Sorin Bolos is a new contributor. Be nice, and check out our Code of Conduct.













                    Sorin Bolos is a new contributor. Be nice, and check out our Code of Conduct.












                    Sorin Bolos is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Quantum Computing Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fquantumcomputing.stackexchange.com%2fquestions%2f6477%2fhow-to-compute-the-inverse-of-an-operation-in-q%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                    Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                    Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...