<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Malcolm Low</title>
    <description>The latest articles on DEV Community by Malcolm Low (@malcolmlow).</description>
    <link>https://dev.to/malcolmlow</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3894359%2F50ab9e6e-a918-40f1-b3b5-a7526195ffa6.jpg</url>
      <title>DEV Community: Malcolm Low</title>
      <link>https://dev.to/malcolmlow</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/malcolmlow"/>
    <language>en</language>
    <item>
      <title>Quantum Teleportation, and Why It Isn't Cloning</title>
      <dc:creator>Malcolm Low</dc:creator>
      <pubDate>Wed, 24 Jun 2026 11:04:09 +0000</pubDate>
      <link>https://dev.to/malcolmlow/quantum-teleportation-and-why-it-isnt-cloning-1fdl</link>
      <guid>https://dev.to/malcolmlow/quantum-teleportation-and-why-it-isnt-cloning-1fdl</guid>
      <description>&lt;p&gt;&lt;em&gt;Part of the Techucation Quantum Series.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Teleportation is the most over-sold word in quantum computing. It conjures Star Trek transporters and faster-than-light messaging, and almost every popular account quietly implies you end up with a &lt;em&gt;copy&lt;/em&gt; of the original. You do not. Quantum teleportation moves an unknown quantum state from one qubit to another while &lt;strong&gt;destroying&lt;/strong&gt; the original, and that destruction is not an incidental detail. It is the mechanism that keeps the protocol on the right side of the no-cloning theorem.&lt;/p&gt;

&lt;h2&gt;
  
  
  A quick word on no-cloning
&lt;/h2&gt;

&lt;p&gt;This whole protocol is haunted by the &lt;strong&gt;no-cloning theorem&lt;/strong&gt;: there is no operation that copies an arbitrary &lt;em&gt;unknown&lt;/em&gt; quantum state. I worked through the proof and its consequences in a recent post, &lt;a href="https://malcolmlow.com/2026/06/07/the-no-cloning-theorem-in-quantum-computing-why-you-cant-copy-a-qubit/" rel="noopener noreferrer"&gt;The No-Cloning Theorem in Quantum Computing: Why You Can't Copy a Qubit&lt;/a&gt;, so I won't re-derive it here.&lt;/p&gt;

&lt;p&gt;The single fact we need: &lt;strong&gt;you cannot deterministically duplicate an unknown qubit.&lt;/strong&gt; The qualifiers matter, because teleportation lives in the gaps between them. The theorem forbids copying &lt;em&gt;unknown&lt;/em&gt; states (a known state you can re-prepare at will), it forbids &lt;em&gt;deterministic, perfect&lt;/em&gt; copies, and it is a statement about &lt;em&gt;unitary&lt;/em&gt; operations — and measurement, which teleportation leans on at the decisive moment, is not unitary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why teleportation isn't cloning
&lt;/h2&gt;

&lt;p&gt;The distinction in one sentence: &lt;strong&gt;cloning would leave &lt;code&gt;|ψ⟩&lt;/code&gt; in two places; teleportation leaves it in exactly one.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Partway through the protocol, Alice's message qubit is &lt;em&gt;measured&lt;/em&gt;. Measurement collapses it into a classical basis state — a plain &lt;code&gt;|0⟩&lt;/code&gt; or &lt;code&gt;|1⟩&lt;/code&gt; carrying none of the original amplitudes. By the time Bob's qubit holds &lt;code&gt;|ψ⟩&lt;/code&gt;, Alice's qubit demonstrably does not. The state was relocated, and the accounting is exact: one copy in, one copy out. No moment ever exists where two qubits both carry &lt;code&gt;|ψ⟩&lt;/code&gt;, so there is nothing for the no-cloning theorem to object to.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This also kills the faster-than-light fantasy. The protocol forces Alice to send Bob two ordinary classical bits. Until they arrive, Bob's qubit is information-free — we will see that fall out of the algebra below.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The complete circuit
&lt;/h2&gt;

&lt;p&gt;Read it left to right; the protocol splits into three stages. The message qubit &lt;code&gt;q0&lt;/code&gt; starts in the unknown state &lt;code&gt;|ψ⟩&lt;/code&gt;, while &lt;code&gt;q1&lt;/code&gt; and &lt;code&gt;q2&lt;/code&gt; both start in &lt;code&gt;|0⟩&lt;/code&gt;. In the diagram, &lt;code&gt;*&lt;/code&gt; marks a control and &lt;code&gt;(+)&lt;/code&gt; a CNOT target.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3rdgpnptd6glg1pftaz9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3rdgpnptd6glg1pftaz9.jpg" alt=" " width="800" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 1 — Bell pair.&lt;/strong&gt; Alice and Bob share an entangled pair: an &lt;code&gt;H&lt;/code&gt; on &lt;code&gt;q1&lt;/code&gt; followed by a CNOT from &lt;code&gt;q1&lt;/code&gt; onto &lt;code&gt;q2&lt;/code&gt; prepares &lt;code&gt;(|00⟩ + |11⟩)/√2&lt;/code&gt; across the two halves.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 2 — Alice measures.&lt;/strong&gt; Alice folds her message into the pair (a CNOT from &lt;code&gt;q0&lt;/code&gt; onto &lt;code&gt;q1&lt;/code&gt;, then an &lt;code&gt;H&lt;/code&gt; on &lt;code&gt;q0&lt;/code&gt;) and measures both of her qubits, collapsing them to two classical bits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 3 — Bob corrects.&lt;/strong&gt; Depending on those two bits, Bob applies an &lt;code&gt;X&lt;/code&gt; and/or a &lt;code&gt;Z&lt;/code&gt; to &lt;code&gt;q2&lt;/code&gt; — the &lt;code&gt;X&lt;/code&gt; controlled by Alice's &lt;code&gt;q1&lt;/code&gt; bit, the &lt;code&gt;Z&lt;/code&gt; by her &lt;code&gt;q0&lt;/code&gt; bit — and &lt;code&gt;q2&lt;/code&gt; emerges as &lt;code&gt;|ψ⟩&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The protocol in bra-ket and tensor form
&lt;/h2&gt;

&lt;p&gt;Three qubits: &lt;code&gt;q0&lt;/code&gt; carries &lt;code&gt;|ψ⟩ = α|0⟩ + β|1⟩&lt;/code&gt;, &lt;code&gt;q1&lt;/code&gt; is Alice's half of the Bell pair, and &lt;code&gt;q2&lt;/code&gt; is Bob's half. They pre-share &lt;code&gt;|Φ+⟩ = (|00⟩ + |11⟩)/√2&lt;/code&gt; on &lt;code&gt;q1 q2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1 — the starting state.&lt;/strong&gt; Tensor the message against the Bell pair:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|ψ⟩ = α|0⟩ + β|1⟩            (the unknown message on q0)

|ψ⟩ ⊗ |Φ+⟩ = (α|0⟩ + β|1⟩) ⊗ (|00⟩ + |11⟩)/√2
           = (1/√2) [ α|000⟩ + α|011⟩ + β|100⟩ + β|111⟩ ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2 — Alice's CNOT&lt;/strong&gt; (control q0, target q1):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CNOT (control q0, target q1)  flips q1 wherever q0 = 1:

= (1/√2) [ α|000⟩ + α|011⟩ + β|110⟩ + β|101⟩ ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3 — Alice's Hadamard on q0.&lt;/strong&gt; Substitute &lt;code&gt;|0⟩ → (|0⟩+|1⟩)/√2&lt;/code&gt; and &lt;code&gt;|1⟩ → (|0⟩−|1⟩)/√2&lt;/code&gt;, then collect by the value of &lt;code&gt;(q0 q1)&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;H on q0, then collect by the pair Alice will measure (q0 q1):

= (1/2) [ |00⟩ (α|0⟩ + β|1⟩)    ← case A
        + |01⟩ (α|1⟩ + β|0⟩)    ← case B
        + |10⟩ (α|0⟩ − β|1⟩)    ← case C
        + |11⟩ (α|1⟩ − β|0⟩) ]  ← case D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each bracketed &lt;code&gt;q2&lt;/code&gt; state is the original &lt;code&gt;|ψ⟩&lt;/code&gt; acted on by a known Pauli. Alice measures, gets one of four outcomes (each with probability 1/4), sends the two bits to Bob, and Bob undoes the Pauli. The &lt;strong&gt;Case&lt;/strong&gt; column ties each row back to the matching line in Step 3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt; Case | Alice measures (q0 q1) | Bob holds on q2 | Relation to |ψ⟩ | Bob applies 
------+------------------------+-----------------+-----------------+-------------
 A    | 00                     | α|0⟩ + β|1⟩     | I |ψ⟩           | nothing     
 B    | 01                     | α|1⟩ + β|0⟩     | X |ψ⟩           | X           
 C    | 10                     | α|0⟩ − β|1⟩     | Z |ψ⟩           | Z           
 D    | 11                     | α|1⟩ − β|0⟩     | ZX |ψ⟩          | X then Z    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bob applies &lt;code&gt;Z^m0 X^m1&lt;/code&gt; — an &lt;code&gt;X&lt;/code&gt; if &lt;code&gt;m1 = 1&lt;/code&gt;, then a &lt;code&gt;Z&lt;/code&gt; if &lt;code&gt;m0 = 1&lt;/code&gt; — and every branch lands back on &lt;code&gt;α|0⟩ + β|1⟩ = |ψ⟩&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Qiskit — classical feed-forward
&lt;/h2&gt;

&lt;p&gt;This version measures mid-circuit and uses real classical conditioning via &lt;code&gt;if_test&lt;/code&gt;. The verification trick: rather than read out Bob's state, apply the &lt;em&gt;inverse&lt;/em&gt; of the preparation to &lt;code&gt;q2&lt;/code&gt;. If teleportation worked, that must collapse &lt;code&gt;q2&lt;/code&gt; to &lt;code&gt;|0⟩&lt;/code&gt; on every shot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;qiskit&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;QuantumRegister&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ClassicalRegister&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;transpile&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;qiskit.circuit.library&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;StatePreparation&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;qiskit.quantum_info&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;random_statevector&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;qiskit_aer&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AerSimulator&lt;/span&gt;

&lt;span class="c1"&gt;# Unknown state to teleport (StatePreparation is unitary -&amp;gt; invertible)
&lt;/span&gt;&lt;span class="n"&gt;psi&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;random_statevector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;prep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;StatePreparation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;psi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;q&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumRegister&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;q&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;# q0 message, q1 Alice, q2 Bob
&lt;/span&gt;&lt;span class="n"&gt;mz&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ClassicalRegister&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mz&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# q0 result -&amp;gt; drives Z
&lt;/span&gt;&lt;span class="n"&gt;mx&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ClassicalRegister&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mx&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# q1 result -&amp;gt; drives X
&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ClassicalRegister&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;out&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# verification bit
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mz&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prep&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;        &lt;span class="c1"&gt;# 1. load |ψ⟩ onto q0
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;        &lt;span class="c1"&gt;# 2. Bell pair on (q1,q2)
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                      &lt;span class="c1"&gt;# 3. Alice's basis change
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mz&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mx&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;if_test&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;mx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;                 &lt;span class="c1"&gt;# 4. Bob's corrections
&lt;/span&gt;    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;if_test&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;mz&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;z&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prep&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;inverse&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;            &lt;span class="c1"&gt;# 5. un-prepare on Bob: must read 0
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;counts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AerSimulator&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;transpile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;AerSimulator&lt;/span&gt;&lt;span class="p"&gt;()),&lt;/span&gt; &lt;span class="n"&gt;shots&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4000&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;result&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;get_counts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;clean&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# leftmost bit = out
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Teleportation verified:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;clean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;out&lt;/code&gt; bit comes back &lt;code&gt;0&lt;/code&gt; on 100% of shots regardless of the random &lt;code&gt;(mx, mz)&lt;/code&gt; branch — exactly the claim that Bob reconstructs &lt;code&gt;|ψ⟩&lt;/code&gt; in every case.&lt;/p&gt;

&lt;h2&gt;
  
  
  No faster-than-light, and the takeaway
&lt;/h2&gt;

&lt;p&gt;Before Bob learns &lt;code&gt;(m0, m1)&lt;/code&gt;, his qubit is an equal mixture of the four branch states. Averaging the four projectors gives the Pauli twirl:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ρ_Bob = (1/4)( |ψ⟩⟨ψ| + X|ψ⟩⟨ψ|X
              + Z|ψ⟩⟨ψ|Z + XZ|ψ⟩⟨ψ|ZX )  =  I/2   for every |ψ⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for &lt;em&gt;any&lt;/em&gt; &lt;code&gt;|ψ⟩&lt;/code&gt;. Bob's local state is identical no matter what Alice sent, so no information has reached him yet. The classical bits are not a formality — they are the only thing that carries the state across, and they travel no faster than light.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Takeaway.&lt;/strong&gt; No-cloning forbids duplicating an unknown qubit (&lt;a href="https://malcolmlow.com/2026/06/07/the-no-cloning-theorem-in-quantum-computing-why-you-cant-copy-a-qubit/" rel="noopener noreferrer"&gt;proof here&lt;/a&gt;). Teleportation never attempts a copy: it entangles the message with a shared Bell pair, measures the original out of existence, and ships two classical bits naming which of four Pauli corrections rebuilds the state on the other end. Exactly one copy before, exactly one after. No-cloning is not a bug the protocol works around — it is the reason the protocol has to look the way it does.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://malcolmlow.com/2026/06/24/quantum-teleportation-and-why-it-isnt-cloning/" rel="noopener noreferrer"&gt;malcolmlow.com&lt;/a&gt;. Built with Qiskit. This article was written with the assistance of Claude by Anthropic.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>quantumcomputing</category>
      <category>qiskit</category>
      <category>python</category>
      <category>physics</category>
    </item>
    <item>
      <title>Move Your WordPress.com Domain to Cloudflare and Halve the Renewal</title>
      <dc:creator>Malcolm Low</dc:creator>
      <pubDate>Thu, 11 Jun 2026 04:33:59 +0000</pubDate>
      <link>https://dev.to/malcolmlow/move-your-wordpresscom-domain-to-cloudflare-and-halve-the-renewal-4a9n</link>
      <guid>https://dev.to/malcolmlow/move-your-wordpresscom-domain-to-cloudflare-and-halve-the-renewal-4a9n</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This post was originally published on &lt;a href="https://malcolmlow.com/2026/06/11/move-your-wordpress-com-domain-to-cloudflare-and-halve-the-renewal/" rel="noopener noreferrer"&gt;Techucation&lt;/a&gt;, my blog at malcolmlow.com. Cross-posted here for the dev.to community.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;My WordPress.com domain renewal notice came in at &lt;strong&gt;£16/year&lt;/strong&gt;, with auto-renew switched off and the expiry only a couple of days away. That is a fine price for convenience, but the same name sits on Cloudflare Registrar at wholesale cost with no markup. This post walks through the move end to end, including the one step that quietly breaks things if you rush it, and lays out the real cost difference.&lt;/p&gt;

&lt;p&gt;The short version: you do not "renew at Cloudflare". You &lt;strong&gt;transfer&lt;/strong&gt; the domain to Cloudflare, which extends the registration by a year in the process. The saving is real, but the order of operations matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The cost case
&lt;/h2&gt;

&lt;p&gt;Cloudflare Registrar charges exactly what the registry charges them, with zero markup, and bundles WHOIS privacy for free. Retail registrars add a margin on top. For a &lt;code&gt;.net&lt;/code&gt; the difference looks like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Item&lt;/th&gt;
&lt;th&gt;WordPress.com&lt;/th&gt;
&lt;th&gt;Cloudflare Registrar&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;.net renewal (1 yr)&lt;/td&gt;
&lt;td&gt;£16 (approx US$20)&lt;/td&gt;
&lt;td&gt;approx US$10.44 (at cost)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Markup&lt;/td&gt;
&lt;td&gt;Retail margin&lt;/td&gt;
&lt;td&gt;None (wholesale pass-through)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WHOIS privacy&lt;/td&gt;
&lt;td&gt;Included&lt;/td&gt;
&lt;td&gt;Included, free&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Approx 5-year cost&lt;/td&gt;
&lt;td&gt;approx US$100&lt;/td&gt;
&lt;td&gt;approx US$52&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Figures are indicative for mid-2026.&lt;/strong&gt; Because Cloudflare is at cost, your renewal tracks the registry wholesale rate, so it moves up if the registry (Verisign for &lt;code&gt;.net&lt;/code&gt;) raises prices. The trade-off: Cloudflare requires the domain to run on Cloudflare DNS.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  2. The gotcha: transfer, not renew, and DNS moves first
&lt;/h2&gt;

&lt;p&gt;Two things trip people up:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You cannot renew a domain at a registrar where it is not registered.&lt;/strong&gt; To get Cloudflare pricing you transfer the domain in. A gTLD transfer (.com, .net, .org) automatically adds one year, so it replaces the renewal rather than stacking on top of it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cloudflare will not let you transfer the registration until the domain is already running on Cloudflare DNS.&lt;/strong&gt; So the real sequence is DNS first, registrar second, with any redirect rebuilt in the middle so the site never goes dark.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Mind the expiry window.&lt;/strong&gt; Do not start this within a few days of expiry and then walk away. A transfer left to auto-complete can take up to 5 days. If you are close to the date, expedite it (see step 6) rather than waiting out the clock.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  3. Step by step
&lt;/h2&gt;

&lt;p&gt;The full order of operations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1  Unlock the domain at WordPress.com, get the EPP / auth code
2  Add the domain as a Free zone in Cloudflare
3  Stage the redirect in Cloudflare (before flipping nameservers)
4  Change nameservers at WordPress.com to Cloudflare's pair
5  Wait for the Cloudflare zone to go Active
6  Initiate the transfer in Cloudflare, paste the EPP code, pay
7  Approve / expedite the transfer on the WordPress.com side
8  Verify: registrar, new expiry, redirect, DNSSEC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 1.&lt;/strong&gt; In WordPress.com under Upgrades &amp;gt; Domains, open the domain, turn off Transfer lock, then start the transfer-out flow far enough to reveal the EPP / auth code. Copy it. Do not let WordPress walk you all the way through its own wizard, you only want the code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2.&lt;/strong&gt; In the Cloudflare dashboard, Add a domain, choose the Free plan. Cloudflare scans existing DNS and assigns you two nameservers like &lt;code&gt;name.ns.cloudflare.com&lt;/code&gt;. Note them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3.&lt;/strong&gt; If the domain is a redirect (common when it just points at another site of yours), rebuild that redirect in Cloudflare now while it sits idle. See section 4.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4.&lt;/strong&gt; Back at WordPress.com, switch the nameservers from WordPress to the two Cloudflare nameservers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5.&lt;/strong&gt; Cloudflare flips the zone to Active once it sees the nameserver change, usually under an hour. The transfer option stays greyed out until then.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6.&lt;/strong&gt; Once Active, go to Domain Registration &amp;gt; Transfer Domains, select the domain, paste the EPP code, and pay the at-cost fee. This payment includes the added year.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7.&lt;/strong&gt; Watch for the confirmation from the losing registrar. WordPress.com surfaces a Transfer Management page with an &lt;strong&gt;Accept Transfer&lt;/strong&gt; button. Clicking it skips the 5-day wait and completes the transfer in minutes.&lt;/p&gt;

&lt;p&gt;Done: the registry should now show the registrar as Cloudflare, status Active, and the expiry rolled forward by a year.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The redirect-only trap
&lt;/h2&gt;

&lt;p&gt;If your domain only exists to redirect to another site, the imported records (the host's A records and a couple of CNAMEs) become redundant once you build a Cloudflare Redirect Rule. Tempting to delete them all for a tidy zone. Here is the trap:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A Cloudflare Redirect Rule only fires on traffic that reaches Cloudflare's edge. Traffic only reaches the edge if the hostname resolves to a &lt;strong&gt;proxied&lt;/strong&gt; record (orange cloud). Delete every record and the name resolves to nothing, so the redirect goes dark.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The fix is to keep one proxied placeholder for the rule to attach to:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;th&gt;Proxy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;@&lt;/td&gt;
&lt;td&gt;192.0.2.1&lt;/td&gt;
&lt;td&gt;Proxied&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CNAME&lt;/td&gt;
&lt;td&gt;www&lt;/td&gt;
&lt;td&gt;@&lt;/td&gt;
&lt;td&gt;Proxied (only if you want www)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TXT&lt;/td&gt;
&lt;td&gt;@&lt;/td&gt;
&lt;td&gt;"google-site-verification=..."&lt;/td&gt;
&lt;td&gt;DNS only&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;192.0.2.1&lt;/code&gt; is a reserved TEST-NET address that never routes anywhere, which is exactly what you want: the proxy intercepts the request before that IP is ever used. Then a single Redirect Rule (Rules &amp;gt; Redirect Rules) handles the rest:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Setting&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;When (match)&lt;/td&gt;
&lt;td&gt;hostname ends with example.net&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Then (action)&lt;/td&gt;
&lt;td&gt;301 to &lt;a href="https://example.com" rel="noopener noreferrer"&gt;https://example.com&lt;/a&gt; + path&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Preserve query string&lt;/td&gt;
&lt;td&gt;On&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Keep the TXT verification record as DNS only. It does not need to resolve to anything, it just needs to exist.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. After the transfer
&lt;/h2&gt;

&lt;p&gt;Three things to settle once the registrar shows Cloudflare:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Auto-renew.&lt;/strong&gt; Optional, but turning it on (Domain Registration &amp;gt; your domain) means you never repeat the two-days-from-expiry scramble. If you leave it off, set yourself a reminder a few weeks before the date.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DNSSEC.&lt;/strong&gt; Worth enabling for the added integrity protection. Because Cloudflare is now both your DNS and your registrar, the DS record is published to the registry automatically, so it activates without you touching the registrar by hand. Give it from a few minutes up to a couple of hours to show as signed at the registry.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Registrar lock.&lt;/strong&gt; On by default at Cloudflare, so that one is already handled.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;One caution with DNSSEC:&lt;/strong&gt; once the DS record is published, do not move nameservers away from Cloudflare or disable DNSSEC out of order. Breaking the signature chain is the classic way to make a domain go dark, because validating resolvers will reject it. As long as DNS stays on Cloudflare, you are fine.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Net result
&lt;/h2&gt;

&lt;p&gt;Same domain, half the renewal cost, a year added, and the registrar consolidated with your DNS. The only part that needs care is the DNS-first ordering and not over-deleting the redirect records. Everything else is a few clicks and a short wait.&lt;/p&gt;

</description>
      <category>cloudflare</category>
      <category>dns</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Deutsch Algorithm Revisited: Quantum vs Classical Implementation in Qiskit</title>
      <dc:creator>Malcolm Low</dc:creator>
      <pubDate>Sun, 07 Jun 2026 10:12:11 +0000</pubDate>
      <link>https://dev.to/malcolmlow/deutsch-algorithm-revisited-quantum-vs-classical-implementation-in-qiskit-4ii2</link>
      <guid>https://dev.to/malcolmlow/deutsch-algorithm-revisited-quantum-vs-classical-implementation-in-qiskit-4ii2</guid>
      <description>&lt;p&gt;In the &lt;a href="https://malcolmlow.com/2025/12/09/deutschs-algorithm-in-quantum-computing-the-4-cases/" rel="noopener noreferrer"&gt;previous post on the Deutsch algorithm&lt;/a&gt;, we covered the theory. Here we implement both the classical and quantum approaches in Qiskit so the quantum advantage is visible in working code: the same problem solved with fewer oracle queries than any classical method can manage.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Challenge
&lt;/h2&gt;

&lt;p&gt;Given a black-box function &lt;code&gt;f: {0,1} → {0,1}&lt;/code&gt;, determine whether it is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Constant&lt;/strong&gt;: f(0) = f(1) (always returns 0, or always returns 1)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Balanced&lt;/strong&gt;: f(0) ≠ f(1) (returns 0 for one input, 1 for the other)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The whole question is how many times you must query the function:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;Queries required&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Classical&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Quantum&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Complete Qiskit Implementation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Oracle functions
&lt;/h3&gt;

&lt;p&gt;First, build the oracle functions representing all possible single-bit Boolean functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;qiskit&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;QuantumRegister&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ClassicalRegister&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;qiskit_aer&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AerSimulator&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_constant_oracle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;constant_value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Creates a constant oracle (returns 0 or 1 for all inputs)&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;oracle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Constant_&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;constant_value&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;constant_value&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Flip the output qubit
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;oracle&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_balanced_oracle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;balance_type&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Creates a balanced oracle&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;oracle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Balanced_&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;balance_type&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;balance_type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;identity&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# f(x) = x
&lt;/span&gt;        &lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;balance_type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;negation&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# f(x) = NOT x
&lt;/span&gt;        &lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;oracle&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Classical approach: two queries required
&lt;/h3&gt;

&lt;p&gt;The classical algorithm must query the oracle twice, once for f(0) and once for f(1):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;classical_deutsch_query1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;First query: Evaluate f(0)&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;qr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumRegister&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;q&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ClassicalRegister&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;c&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;qr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Input: x = 0 (already initialized to |0&amp;gt;)
&lt;/span&gt;    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;inplace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Measure output to get f(0)
&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;qc&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;classical_deutsch_query2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Second query: Evaluate f(1)&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;qr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumRegister&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;q&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ClassicalRegister&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;c&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;qr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Input: x = 1
&lt;/span&gt;    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;inplace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Measure output to get f(1)
&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;qc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Quantum approach: one query suffices
&lt;/h3&gt;

&lt;p&gt;The quantum Deutsch algorithm uses superposition and interference to answer with a single oracle query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deutsch_algorithm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Implements the Deutsch algorithm - requires only ONE query&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;qr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumRegister&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;q&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ClassicalRegister&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;c&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;qr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Step 1: Initialize q[1] to |1&amp;gt;
&lt;/span&gt;    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;# Step 2: Apply Hadamard gates (create superposition)
&lt;/span&gt;    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;# Step 3: Apply the oracle (SINGLE QUERY!)
&lt;/span&gt;    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;inplace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;# Step 4: Apply Hadamard to input qubit
&lt;/span&gt;    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;# Step 5: Measure
&lt;/span&gt;    &lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;qc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Running the comparison
&lt;/h3&gt;

&lt;p&gt;Now test all four possible oracles with both approaches:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;oracles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Constant 0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;create_constant_oracle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Constant 1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;create_constant_oracle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Balanced (Identity)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;create_balanced_oracle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;identity&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Balanced (Negation)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;create_balanced_oracle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;negation&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;simulator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AerSimulator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;oracle&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;oracles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Classical: 2 queries
&lt;/span&gt;    &lt;span class="n"&gt;qc1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;classical_deutsch_query1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;result1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;simulator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;qc1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shots&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;result&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;f_0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_counts&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;())[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

    &lt;span class="n"&gt;qc2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;classical_deutsch_query2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;result2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;simulator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;qc2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shots&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;result&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;f_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_counts&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;())[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

    &lt;span class="n"&gt;classical_result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CONSTANT&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;f_0&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;f_1&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;BALANCED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="c1"&gt;# Quantum: 1 query
&lt;/span&gt;    &lt;span class="n"&gt;qc_quantum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;deutsch_algorithm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oracle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;result_quantum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;simulator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;qc_quantum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shots&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;result&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;counts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result_quantum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_counts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;quantum_result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CONSTANT&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;counts&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;BALANCED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: Classical=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;classical_result&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, Quantum=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;quantum_result&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Circuit Diagrams
&lt;/h2&gt;

&lt;p&gt;The full figures are rendered in the &lt;a href="https://malcolmlow.com/2025/12/20/deutsch-algorithm-revisited-quantum-vs-classical-implementation-in-qiskit/" rel="noopener noreferrer"&gt;original post&lt;/a&gt;; the structure of each is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Classical Query 1, f(0):&lt;/strong&gt; q[0] stays in |0⟩, the oracle processes the input, and q[1] is measured to read f(0).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Classical Query 2, f(1):&lt;/strong&gt; an X gate flips q[0] to |1⟩, the oracle processes it, and q[1] is measured to read f(1).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quantum Deutsch (single query):&lt;/strong&gt; initialise |01⟩, Hadamards on both wires create superposition, a single oracle query, a final Hadamard on q[0], then measure q[0].&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The key structural difference: the classical circuits measure the &lt;strong&gt;output&lt;/strong&gt; qubit q[1] to read function values, while the quantum circuit measures the &lt;strong&gt;input&lt;/strong&gt; qubit q[0] after interference. That is what lets a single query reveal a global property of the function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sample Output
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;======================================================================
Testing: Constant 0 Oracle
======================================================================

[CLASSICAL APPROACH - Requires 2 queries]
  Query 1: f(0) = 0
  Query 2: f(1) = 0
  Result: Function is CONSTANT
  Total queries needed: 2

[QUANTUM APPROACH - Requires only 1 query]
  Measurement results: {'0': 1000}
  Result: Function is CONSTANT
  Total queries needed: 1

  Both methods agree: True

======================================================================
Testing: Balanced (Identity) Oracle
======================================================================

[CLASSICAL APPROACH - Requires 2 queries]
  Query 1: f(0) = 0
  Query 2: f(1) = 1
  Result: Function is BALANCED
  Total queries needed: 2

[QUANTUM APPROACH - Requires only 1 query]
  Measurement results: {'1': 1000}
  Result: Function is BALANCED
  Total queries needed: 1

  Both methods agree: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Understanding the Quantum Advantage
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Classical approach:&lt;/strong&gt; evaluate f(0), evaluate f(1), compare the two results. Two queries required; you must check both inputs individually.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quantum approach:&lt;/strong&gt; query with a superposition of both inputs, use interference to extract the global property, then measure. One query required; it exploits quantum parallelism.&lt;/p&gt;

&lt;p&gt;The quantum algorithm queries the oracle with a superposition of both inputs simultaneously (|0⟩ + |1⟩), then uses interference to extract a global property of the function without evaluating it on individual inputs. The single measurement directly tells you whether the function is constant or balanced.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measurement Interpretation
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Measurement&lt;/th&gt;
&lt;th&gt;Function type&lt;/th&gt;
&lt;th&gt;Explanation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;|0⟩&lt;/td&gt;
&lt;td&gt;Constant&lt;/td&gt;
&lt;td&gt;Constructive interference, f(0) ⊕ f(1) = 0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;|1⟩&lt;/td&gt;
&lt;td&gt;Balanced&lt;/td&gt;
&lt;td&gt;Destructive interference, f(0) ⊕ f(1) = 1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Running the Code
&lt;/h2&gt;

&lt;p&gt;Install Qiskit and Aer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;qiskit qiskit-aer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run the comparison script; it outputs the result for all four oracle types.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This implementation shows the Deutsch advantage concretely: a 2x reduction in oracle queries (from 2 to 1), the first algorithm to demonstrate quantum advantage over classical, and a foundational technique introducing superposition, interference, and phase kickback. The speedup is modest for this toy problem, but the same idea (query with superposition, extract a global property through interference) scales up to Deutsch-Jozsa, Simon's algorithm, and Shor's factoring.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Part of the Quantum Series 2026. Originally published on &lt;a href="https://malcolmlow.com/2025/12/20/deutsch-algorithm-revisited-quantum-vs-classical-implementation-in-qiskit/" rel="noopener noreferrer"&gt;Techucation&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>quantum</category>
      <category>qiskit</category>
      <category>python</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Deutsch's Algorithm in Quantum Computing: The 4 Cases</title>
      <dc:creator>Malcolm Low</dc:creator>
      <pubDate>Sun, 07 Jun 2026 10:11:35 +0000</pubDate>
      <link>https://dev.to/malcolmlow/deutschs-algorithm-in-quantum-computing-the-4-cases-5dae</link>
      <guid>https://dev.to/malcolmlow/deutschs-algorithm-in-quantum-computing-the-4-cases-5dae</guid>
      <description>&lt;p&gt;Deutsch's Algorithm determines whether a function &lt;em&gt;f(x)&lt;/em&gt; is &lt;strong&gt;constant&lt;/strong&gt; or &lt;strong&gt;balanced&lt;/strong&gt; using only a single query. Before getting to the quantum circuit, it helps to see how the four possible single-bit functions are physically built.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 4 Possible Functions
&lt;/h2&gt;

&lt;p&gt;With one input bit, there are exactly four Boolean functions. Two are constant (the output ignores the input) and two are balanced (the output depends on the input). In each oracle the bottom input is set to 0 so the output wire carries exactly f(x).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Constant Zero&lt;/td&gt;
&lt;td&gt;f(x) = 0&lt;/td&gt;
&lt;td&gt;Constant (identity, no gates)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Constant One&lt;/td&gt;
&lt;td&gt;f(x) = 1&lt;/td&gt;
&lt;td&gt;Constant (X on the output wire)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Balanced ID&lt;/td&gt;
&lt;td&gt;f(x) = x&lt;/td&gt;
&lt;td&gt;Balanced (CNOT)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Balanced NOT&lt;/td&gt;
&lt;td&gt;f(x) = ¬x&lt;/td&gt;
&lt;td&gt;Balanced (X, CNOT, X)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  The General Oracle (U_f)
&lt;/h2&gt;

&lt;p&gt;Every oracle is wrapped in the standard reversible form. It leaves the input register alone and XORs f(x) into the output register:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;U_f |x⟩|y⟩  =  |x⟩ |y ⊕ f(x)⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Complete Circuit
&lt;/h2&gt;

&lt;p&gt;To detect the function type in one shot, initialise the bottom wire to |1⟩ and use Hadamard gates to build superposition on both wires before and after the oracle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|0⟩ ──[H]──╤═════╤──[H]──[M]
           │ U_f │
|1⟩ ──[H]──╧═════╧───────────
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The top wire is the control, the bottom wire is the target prepared in |−⟩. The oracle's (−1)^f(x) phase is kicked back onto the top wire, and the final Hadamard converts that phase difference into a measurable 0 or 1.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mathematical Proof
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Initialisation:   |ψ₀⟩ = |0⟩|1⟩

2. Superposition:    |ψ₁⟩ = |+⟩|−⟩ = ½(|0⟩ + |1⟩)(|0⟩ − |1⟩)

3. The kickback:     U_f |x⟩|−⟩ = (−1)^f(x) |x⟩|−⟩
                     the function output is pushed into the phase of the top qubit.

4. Global state:     |ψ₂⟩ = (1/√2) [ (−1)^f(0)|0⟩ + (−1)^f(1)|1⟩ ] ⊗ |−⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Final Measurement
&lt;/h2&gt;

&lt;p&gt;After the last Hadamard on the top qubit, the relative phase between the two terms decides the outcome:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If &lt;strong&gt;f(0) = f(1)&lt;/strong&gt; (constant) the top qubit collapses to ±|+⟩, so the final H gives &lt;strong&gt;measure 0&lt;/strong&gt;.&lt;br&gt;
If &lt;strong&gt;f(0) ≠ f(1)&lt;/strong&gt; (balanced) it collapses to ±|−⟩, so the final H gives &lt;strong&gt;measure 1&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A single oracle query distinguishes constant from balanced, where any classical approach needs two. That one-query advantage is the seed of Deutsch-Jozsa, Simon's, and ultimately Shor's algorithm.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Part of the Quantum Series 2026. Originally published on &lt;a href="https://malcolmlow.com/2025/12/09/deutschs-algorithm-in-quantum-computing-the-4-cases/" rel="noopener noreferrer"&gt;Techucation&lt;/a&gt;, where the circuit diagrams are rendered in full.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>quantum</category>
      <category>qiskit</category>
      <category>algorithms</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Understanding Phase Kickback in Quantum Computing</title>
      <dc:creator>Malcolm Low</dc:creator>
      <pubDate>Sun, 07 Jun 2026 10:08:40 +0000</pubDate>
      <link>https://dev.to/malcolmlow/understanding-phase-kickback-in-quantum-computing-44en</link>
      <guid>https://dev.to/malcolmlow/understanding-phase-kickback-in-quantum-computing-44en</guid>
      <description>&lt;p&gt;In standard classical logic, a control bit dictates what happens to a target. In quantum mechanics the relationship is symmetric. When the target qubit is in an eigenstate of the gate operator, the eigenvalue phase is &lt;strong&gt;kicked back&lt;/strong&gt; onto the control qubit, leaving the target unchanged while flipping the relative phase of the control. This post derives that result from first principles using the CNOT gate on |+⟩ ⊗ |−⟩.&lt;/p&gt;




&lt;h2&gt;
  
  
  1 · The CNOT Circuit and the Kickback Setup
&lt;/h2&gt;

&lt;p&gt;The circuit places the control qubit in superposition |+⟩ and the target qubit in |−⟩. Since |−⟩ is an eigenstate of X with eigenvalue −1, the kickback occurs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;control:
|+⟩
|−⟩
target:
|−⟩
+
|−⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Key observation:&lt;/strong&gt; The target qubit is unchanged after the CNOT. The control qubit flips from |+⟩ to |−⟩. The phase was kicked back to the control, not forward to the target.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  2 · Full Derivation: |+⟩ ⊗ |−⟩ through CNOT
&lt;/h2&gt;

&lt;p&gt;Step 1 — Define the initial state&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|ψ₀⟩ = |+⟩ ⊗ |−⟩
= (1/√2)(|0⟩ + |1⟩) ⊗ (1/√2)(|0⟩ − |1⟩)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2 — Expand the tensor product&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|ψ₀⟩ = (1/2)[ |00⟩ − |01⟩ + |10⟩ − |11⟩ ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3 — Apply the CNOT gate&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|ψ₁⟩ = (1/2)[ |00⟩ − |01⟩ + |11⟩ − |10⟩ ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4 — Factor and identify the result&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|ψ₁⟩ = (1/2)[ |0⟩(|0⟩ − |1⟩) − |1⟩(|0⟩ − |1⟩) ]
= (1/√2)(|0⟩ − |1⟩) ⊗ (1/√2)(|0⟩ − |1⟩)
= |−⟩ ⊗ |−⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The target qubit is still |−⟩ — unchanged by the CNOT. The control qubit changed from |+⟩ to |−⟩. The −1 eigenvalue of the target has been kicked back as a relative phase onto the control.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  3 · Why Phase Kickback Matters
&lt;/h2&gt;

&lt;p&gt;The math shows that while we applied a gate to the target, the &lt;strong&gt;relative phase&lt;/strong&gt; of the control qubit changed from positive to negative. This is a structural property of controlled unitaries acting on their eigenstates, and it appears at the core of every major quantum algorithm.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Algorithm&lt;/th&gt;
&lt;th&gt;How phase kickback is used&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://malcolmlow.com/2025/12/09/deutschs-algorithm-in-quantum-computing-the-4-cases/" rel="noopener noreferrer"&gt;Deutsch’s Algorithm&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;The oracle kicks a −1 phase onto the control qubit to encode whether f is constant or balanced, extractable with a single H gate measurement.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://malcolmlow.com/2026/03/28/quantum-computing-inversion-about-the-mean/" rel="noopener noreferrer"&gt;Grover’s Algorithm&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;The oracle flips the sign of the target state’s amplitude by kicking a −1 phase back to the control register, enabling amplitude amplification.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shor’s Algorithm&lt;/td&gt;
&lt;td&gt;Quantum Phase Estimation relies entirely on phase kickback to transfer eigenvalue information from the target register to the control register.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The general rule:&lt;/strong&gt; for any unitary U with eigenstate |u⟩ (so U|u⟩ = eⁱᵖ|u⟩), a controlled-U gate with the control in superposition kicks the phase eⁱᵖ back to the control qubit. The target is unchanged.&lt;/p&gt;
&lt;/blockquote&gt;







&lt;p&gt;&lt;em&gt;Part of the Quantum Series 2026. Originally published on &lt;a href="https://malcolmlow.com/2025/12/09/understanding-phase-kickback-in-quantum-computing/" rel="noopener noreferrer"&gt;Techucation&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>quantum</category>
      <category>qiskit</category>
      <category>physics</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Introduction to Quantum Computing: Qubits, Hadamard Gates, and Superposition</title>
      <dc:creator>Malcolm Low</dc:creator>
      <pubDate>Sun, 07 Jun 2026 10:07:46 +0000</pubDate>
      <link>https://dev.to/malcolmlow/introduction-to-quantum-computing-qubits-hadamard-gates-and-superposition-139d</link>
      <guid>https://dev.to/malcolmlow/introduction-to-quantum-computing-qubits-hadamard-gates-and-superposition-139d</guid>
      <description>&lt;p&gt;Classical computers store information in bits that are always exactly 0 or 1. Quantum computers exploit the principles of quantum mechanics to do something fundamentally different: they operate on &lt;strong&gt;qubits&lt;/strong&gt;, which can exist in a superposition of both states simultaneously. The &lt;strong&gt;Hadamard gate&lt;/strong&gt; is the simplest gate that creates this superposition, and understanding it from first principles is the entry point to every quantum algorithm that follows.&lt;/p&gt;




&lt;h2&gt;
  
  
  1 · The Qubit
&lt;/h2&gt;

&lt;p&gt;A qubit is the fundamental unit of quantum information. Unlike a classical bit, a qubit can exist in a &lt;strong&gt;superposition&lt;/strong&gt; of |0⟩ and |1⟩ simultaneously. We write its general state using Dirac (bra-ket) notation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|ψ⟩ = α|0⟩ + β|1⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here α and β are complex numbers called &lt;strong&gt;probability amplitudes&lt;/strong&gt;. They must satisfy the normalisation condition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|α|² + |β|² = 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two computational basis states are represented as column vectors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|0⟩ =
1
0
|1⟩ =
0
1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we measure the qubit in state |ψ⟩ = α|0⟩ + β|1⟩, we get |0⟩ with probability |α|² and |1⟩ with probability |β|². The act of measurement destroys the superposition and collapses the qubit to a definite classical state.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Key distinction:&lt;/strong&gt; The superposition is not just ignorance about a hidden value. The qubit genuinely occupies both states until measured, and this physical reality is what quantum algorithms exploit.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  2 · The Hadamard Gate
&lt;/h2&gt;

&lt;p&gt;The Hadamard gate H is a 2×2 unitary matrix that maps each computational basis state to an equal superposition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;H = (1/√2)
+1 +1
+1 −1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Applying H to each basis state:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Input&lt;/th&gt;
&lt;th&gt;H |input⟩&lt;/th&gt;
&lt;th&gt;Short name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;|0⟩&lt;/td&gt;
&lt;td&gt;(1/√2)( |0⟩ + |1⟩ )&lt;/td&gt;
&lt;td&gt;|+⟩&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;|1⟩&lt;/td&gt;
&lt;td&gt;(1/√2)( |0⟩ − |1⟩ )&lt;/td&gt;
&lt;td&gt;|−⟩&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Both outputs have equal amplitudes of 1/√2, giving a 50% measurement probability for each outcome. The sign difference between |+⟩ and |−⟩ is what drives interference later.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Unitarity check:&lt;/strong&gt; H†H = I. Since H is real and symmetric, H† = H, so H² = I. The Hadamard gate is its own inverse.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  3 · H² = I: Quantum Interference
&lt;/h2&gt;

&lt;p&gt;Applying H twice to |0⟩ returns the qubit to |0⟩. The algebra shows exactly why the |1⟩ amplitudes cancel through destructive interference:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;H(H|0⟩)
= H( (1/√2)(|0⟩ + |1⟩) )
= (1/√2)( H|0⟩ + H|1⟩ )
= (1/√2)( (1/√2)(|0⟩+|1⟩) + (1/√2)(|0⟩−|1⟩) )
= (1/2)( |0⟩ + |1⟩ + |0⟩ − |1⟩ )
= (1/2)( 2|0⟩ )
= |0⟩ ✓
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The +|1⟩ and −|1⟩ terms cancel completely (destructive interference) while the |0⟩ terms add (constructive interference). This is the fundamental mechanism behind quantum algorithms: arranging amplitudes so wrong answers cancel and the correct answer survives.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  4 · Single-Qubit Circuit: H–H–Measure
&lt;/h2&gt;

&lt;p&gt;A single qubit routed through two Hadamard gates and then measured always returns 0 with 100% probability:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;q_0:
H
H
M
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;State&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1. Initialise&lt;/td&gt;
&lt;td&gt;|ψ₀⟩ = |0⟩&lt;/td&gt;
&lt;td&gt;Ground state&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2. First H&lt;/td&gt;
&lt;td&gt;|ψ₁⟩ = (1/√2)(|0⟩+|1⟩)&lt;/td&gt;
&lt;td&gt;Superposition: 50/50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3. Second H&lt;/td&gt;
&lt;td&gt;|ψ₂⟩ = |0⟩&lt;/td&gt;
&lt;td&gt;Interference collapses back&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4. Measure&lt;/td&gt;
&lt;td&gt;Result = 0&lt;/td&gt;
&lt;td&gt;100% probability&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;This is a concrete demonstration that superposition is not just probabilistic noise. The deterministic outcome of 0 is only possible because the two Hadamard gates interact through interference, a purely quantum effect with no classical analogue.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  5 · Tensor Products and Multi-Qubit States
&lt;/h2&gt;

&lt;p&gt;Multi-qubit systems are described using the tensor product (⊗). For two qubits, the four computational basis states are:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Ket&lt;/th&gt;
&lt;th&gt;Tensor form&lt;/th&gt;
&lt;th&gt;Column vector&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;|00⟩&lt;/td&gt;
&lt;td&gt;|0⟩ ⊗ |0⟩&lt;/td&gt;
&lt;td&gt;[1, 0, 0, 0]ᵀ&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;|01⟩&lt;/td&gt;
&lt;td&gt;|0⟩ ⊗ |1⟩&lt;/td&gt;
&lt;td&gt;[0, 1, 0, 0]ᵀ&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;|10⟩&lt;/td&gt;
&lt;td&gt;|1⟩ ⊗ |0⟩&lt;/td&gt;
&lt;td&gt;[0, 0, 1, 0]ᵀ&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;|11⟩&lt;/td&gt;
&lt;td&gt;|1⟩ ⊗ |1⟩&lt;/td&gt;
&lt;td&gt;[0, 0, 0, 1]ᵀ&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The tensor product of two vectors is computed by multiplying each element of the first vector by the entire second vector and stacking the results. For |0⟩ ⊗ |1⟩:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|0⟩ ⊗ |1⟩
= [1, 0]ᵀ ⊗ [0, 1]ᵀ
= [ 1×[0,1]ᵀ ] = [0, 1, 0, 0]ᵀ = |01⟩
[ 0×[0,1]ᵀ ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Dimension growth:&lt;/strong&gt; n qubits span a 2ⁿ-dimensional Hilbert space. A 3-qubit system already has 8 basis states; a 50-qubit system has 2⁵⁰ ≈ 10¹⁵, impossible to store classically.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  6 · Two-Qubit Superposition: H⊗H on |00⟩
&lt;/h2&gt;

&lt;p&gt;Applying independent Hadamard gates to both qubits starting from |00⟩:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;q_0:
H
q_1:
H
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(H⊗H)|00⟩
= (H|0⟩) ⊗ (H|0⟩)
= (1/√2)(|0⟩+|1⟩) ⊗ (1/√2)(|0⟩+|1⟩)
= (1/2)( |00⟩ + |01⟩ + |10⟩ + |11⟩ )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;All four two-qubit basis states appear with equal amplitude &lt;strong&gt;1/2&lt;/strong&gt;. Each has measurement probability (1/2)² = &lt;strong&gt;25%&lt;/strong&gt;. This is the two-qubit analogue of the uniform superposition that opens algorithms like Grover’s.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  7 · Interference in a Two-Qubit H–H Circuit
&lt;/h2&gt;

&lt;p&gt;Applying H⊗H twice to |00⟩ returns it to |00⟩. The interference analysis on each basis state shows the mechanism:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Input to 2nd H⊗H&lt;/th&gt;
&lt;th&gt;After (H⊗H)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;|00⟩&lt;/td&gt;
&lt;td&gt;(1/2)( |00⟩ + |01⟩ + |10⟩ + |11⟩ )&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;|01⟩&lt;/td&gt;
&lt;td&gt;(1/2)( |00⟩ − |01⟩ + |10⟩ − |11⟩ )&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;|10⟩&lt;/td&gt;
&lt;td&gt;(1/2)( |00⟩ + |01⟩ − |10⟩ − |11⟩ )&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;|11⟩&lt;/td&gt;
&lt;td&gt;(1/2)( |00⟩ − |01⟩ − |10⟩ + |11⟩ )&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The initial superposition has equal weight 1/2 on each of the four states. Summing contributions to each output:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Output state&lt;/th&gt;
&lt;th&gt;Amplitude sum (× 1/4)&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;|00⟩&lt;/td&gt;
&lt;td&gt;+1 +1 +1 +1&lt;/td&gt;
&lt;td&gt;4/4 = 1 ✓ constructive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;|01⟩&lt;/td&gt;
&lt;td&gt;+1 −1 +1 −1&lt;/td&gt;
&lt;td&gt;0 destructive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;|10⟩&lt;/td&gt;
&lt;td&gt;+1 +1 −1 −1&lt;/td&gt;
&lt;td&gt;0 destructive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;|11⟩&lt;/td&gt;
&lt;td&gt;+1 −1 −1 +1&lt;/td&gt;
&lt;td&gt;0 destructive&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Only |00⟩ survives. This is the same interference structure that the &lt;a href="https://malcolmlow.com/2026/03/28/quantum-computing-inversion-about-the-mean/" rel="noopener noreferrer"&gt;Grover diffusion operator&lt;/a&gt; exploits at scale: constructive interference on the target state, destructive on all others.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  8 · The H⊗H Matrix and Why It Matters
&lt;/h2&gt;

&lt;p&gt;The combined H⊗H operator is a 4×4 Walsh-Hadamard matrix (scaled by 1/2). Its sign pattern is exactly the two-qubit case of the popcount rule derived in the &lt;a href="https://malcolmlow.com/2026/04/03/quantum-computing-the-walsh-hadamard-matrix-backbone-of-grovers-diffusion-operator/" rel="noopener noreferrer"&gt;Walsh-Hadamard post&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;H⊗H = (1/2)
+1 +1 +1 +1
+1 −1 +1 −1
+1 +1 −1 −1
+1 −1 −1 +1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every quantum algorithm that achieves a speedup over classical computation does so through the same three-phase structure:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Phase&lt;/th&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1. Open&lt;/td&gt;
&lt;td&gt;Hadamard on all qubits&lt;/td&gt;
&lt;td&gt;Create uniform superposition over all 2ⁿ states&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2. Operate&lt;/td&gt;
&lt;td&gt;Oracle / phase manipulation&lt;/td&gt;
&lt;td&gt;Mark or bias the amplitude of the target answer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3. Close&lt;/td&gt;
&lt;td&gt;Hadamard again (+ measurement)&lt;/td&gt;
&lt;td&gt;Interference concentrates probability on the answer&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The bottom line:&lt;/strong&gt; the qubit and the Hadamard gate are the entry point to everything. Grover’s O(√N) search, Shor’s O((log N)³) factoring, and every other quantum speedup ultimately trace back to this interference mechanism operating at scale.&lt;/p&gt;
&lt;/blockquote&gt;







&lt;p&gt;&lt;em&gt;Part of the Quantum Series 2026. Originally published on &lt;a href="https://malcolmlow.com/2025/11/27/introduction-to-quantum-computing-qubits-hadamard-gates-and-superposition/" rel="noopener noreferrer"&gt;Techucation&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>quantum</category>
      <category>qiskit</category>
      <category>physics</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Quantum Computing: CHSH Game Simulator and Bell's Inequality</title>
      <dc:creator>Malcolm Low</dc:creator>
      <pubDate>Sun, 07 Jun 2026 10:07:43 +0000</pubDate>
      <link>https://dev.to/malcolmlow/exploring-quantum-entanglement-the-chsh-game-simulator-3j3d</link>
      <guid>https://dev.to/malcolmlow/exploring-quantum-entanglement-the-chsh-game-simulator-3j3d</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0h8fw454607g5nqlxfj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0h8fw454607g5nqlxfj.png" width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have you ever wondered how quantum mechanics defies everyday intuition? This project demonstrates one of the most striking phenomena in quantum physics: quantum entanglement and its ability to violate classical physics constraints through a playable cooperative game.&lt;/p&gt;

&lt;p&gt;🎮 &lt;strong&gt;&lt;a href="https://myhlow.github.io/chsh-game-simulator" rel="noopener noreferrer"&gt;Try the CHSH Game Simulator&lt;/a&gt;&lt;/strong&gt; | &lt;br&gt;
 📂 &lt;strong&gt;&lt;a href="https://github.com/myhlow/chsh-game-simulator" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  1 · What Is the CHSH Game in Quantum Computing?
&lt;/h2&gt;

&lt;p&gt;The CHSH (Clauser-Horne-Shimony-Holt) game is a cooperative thought experiment that reveals the strange power of quantum entanglement. Two players, Alice and Bob, cannot communicate during the game but may share a pre-agreed strategy or, crucially, a pair of entangled qubits.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Player&lt;/th&gt;
&lt;th&gt;Receives from referee&lt;/th&gt;
&lt;th&gt;Outputs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;Random bit &lt;strong&gt;x&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Bit &lt;strong&gt;a&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;Random bit &lt;strong&gt;y&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Bit &lt;strong&gt;b&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;They win if and only if:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(a + b) mod 2 = x × y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;With classical strategies, Alice and Bob can win at most &lt;strong&gt;75%&lt;/strong&gt; of the time. With a quantum strategy using entangled qubits, they can reach approximately &lt;strong&gt;85.4%&lt;/strong&gt;, violating the classical bound.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  2 · Bell’s Inequality and the CHSH Value
&lt;/h2&gt;

&lt;p&gt;In 1964, John Bell proved that no local hidden variable theory can reproduce all predictions of quantum mechanics. The CHSH inequality formalises Bell’s theorem as a single testable number S:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Theory&lt;/th&gt;
&lt;th&gt;CHSH Value (S)&lt;/th&gt;
&lt;th&gt;Win Rate&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Classical (any local strategy)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;S ≤ 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;75%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Quantum mechanics&lt;/td&gt;
&lt;td&gt;&lt;code&gt;S = 2√2 ≈ 2.828&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;~85.4%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This violation is not a loophole or a trick. It proves that the correlations produced by entangled qubits cannot be explained by any shared classical information, even with pre-agreed randomness. Loophole-free Bell test experiments confirm that quantum entanglement is a genuine physical phenomenon with no classical analogue.&lt;/p&gt;

&lt;h2&gt;
  
  
  3 · Measurement Angles and Quantum Correlation
&lt;/h2&gt;

&lt;p&gt;The quantum advantage arises from choosing measurement bases at specific angles. For the standard |Φ+⟩ Bell state, the optimal angles are:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Player&lt;/th&gt;
&lt;th&gt;Input bit&lt;/th&gt;
&lt;th&gt;Measurement basis&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;x = 0&lt;/td&gt;
&lt;td&gt;0°&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;x = 1&lt;/td&gt;
&lt;td&gt;45°&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;y = 0&lt;/td&gt;
&lt;td&gt;22.5°&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;y = 1&lt;/td&gt;
&lt;td&gt;−22.5°&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The probability that Alice and Bob produce the same outcome is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;P(same) = cos²(δ)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where δ is the angle between their chosen measurement bases. This quantum correlation is what enables them to exceed the 75% classical ceiling. Different Bell states exhibit either &lt;strong&gt;parallel correlation&lt;/strong&gt; (|Φ+⟩, |Ψ+⟩: qubits tend to give the same outcome) or &lt;strong&gt;orthogonal correlation&lt;/strong&gt; (|Φ−⟩, |Ψ−⟩: one qubit effectively rotated 90° relative to the other). The simulator adjusts its probability calculations accordingly for each state.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧪 4 · The Four Bell States
&lt;/h2&gt;

&lt;p&gt;The simulator supports all four maximally entangled Bell states. Each uses optimised measurement angles to achieve the theoretical quantum win rate of ~85%.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;State&lt;/th&gt;
&lt;th&gt;Definition&lt;/th&gt;
&lt;th&gt;Correlation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;|Φ+⟩&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;(|00⟩ + |11⟩) / √2&lt;/td&gt;
&lt;td&gt;Parallel&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;|Φ−⟩&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;(|00⟩ − |11⟩) / √2&lt;/td&gt;
&lt;td&gt;Orthogonal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;|Ψ+⟩&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;(|01⟩ + |10⟩) / √2&lt;/td&gt;
&lt;td&gt;Parallel&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;|Ψ−⟩&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;(|01⟩ − |10⟩) / √2&lt;/td&gt;
&lt;td&gt;Orthogonal&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  🎯 5 · CHSH Game Simulator Features
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Details&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🎯 &lt;strong&gt;Interactive Visualization&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Real-time p5.js visualization showing the entangled state, Alice’s measurement collapse, and Bob’s final measurement. Coloured basis quadrants and correlation indicators included.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🎮 &lt;strong&gt;Strategy Comparison&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Switch between Classical (always outputs 0, max 75%) and Quantum (entangled qubits, ~85.4%) strategies in real time.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🎲 &lt;strong&gt;Flexible Input Controls&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Set Alice’s x and Bob’s y to Random or Fixed (0 or 1) to test specific measurement configurations.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📊 &lt;strong&gt;Real-Time Statistics&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Running totals for rounds played, wins, losses, and win percentage converging toward theoretical predictions.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🔄 &lt;strong&gt;Round History Navigation&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Step through previous rounds to review specific outcomes and trace the quantum measurement process.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Built with:&lt;/strong&gt; React, p5.js, and Claude Code&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  6 · Try the Quantum Entanglement Simulator
&lt;/h2&gt;

&lt;p&gt;A suggested sequence to build intuition:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the &lt;a href="https://myhlow.github.io/chsh-game-simulator" rel="noopener noreferrer"&gt;&lt;strong&gt;simulator&lt;/strong&gt;&lt;/a&gt; and select the &lt;strong&gt;Classical&lt;/strong&gt; strategy. Run 100 rounds and watch the win rate converge toward 75%.&lt;/li&gt;
&lt;li&gt;Switch to the &lt;strong&gt;Quantum&lt;/strong&gt; strategy with the |Φ+⟩ Bell state. Run another 100 rounds and observe the rate climb toward 85%.&lt;/li&gt;
&lt;li&gt;Try the other three Bell states. Note how each state’s correlation type (parallel vs orthogonal) affects the outcome distribution.&lt;/li&gt;
&lt;li&gt;Set Alice and Bob’s inputs to Fixed values to test individual measurement configurations and trace the correlation manually.&lt;/li&gt;
&lt;li&gt;Use Round History to step back through specific rounds and verify the win condition &lt;code&gt;(a + b) mod 2 = x × y&lt;/code&gt; by hand.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  7 · Open Source Code on GitHub
&lt;/h2&gt;

&lt;p&gt;The complete source code is on &lt;a href="https://github.com/myhlow/chsh-game-simulator" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;. Contributions welcome: explore the code, report issues, suggest improvements, or fork it to build your own quantum visualisations.&lt;/p&gt;

&lt;p&gt;Planned enhancements include a 3D Bloch sphere visualisation (Three.js), step-by-step animated transitions, an in-app educational tutorial, a mathematical deep-dive panel, and improved mobile layout.&lt;/p&gt;

&lt;p&gt;The CHSH game demonstrates that quantum entanglement is not a mathematical abstraction but a measurable, observable phenomenon with no classical analogue. This simulator makes that phenomenon interactive and accessible to anyone curious about quantum mechanics.&lt;/p&gt;







&lt;p&gt;&lt;em&gt;Part of the Quantum Series 2026. Originally published on &lt;a href="https://malcolmlow.com/2025/10/20/exploring-quantum-entanglement-chsh-game-simulator/" rel="noopener noreferrer"&gt;Techucation&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>quantum</category>
      <category>entanglement</category>
      <category>physics</category>
      <category>qiskit</category>
    </item>
    <item>
      <title>The No-Cloning Theorem in Quantum Computing: Why You Can't Copy a Qubit</title>
      <dc:creator>Malcolm Low</dc:creator>
      <pubDate>Sun, 07 Jun 2026 09:58:46 +0000</pubDate>
      <link>https://dev.to/malcolmlow/the-no-cloning-theorem-in-quantum-computing-why-you-cant-copy-a-qubit-3m72</link>
      <guid>https://dev.to/malcolmlow/the-no-cloning-theorem-in-quantum-computing-why-you-cant-copy-a-qubit-3m72</guid>
      <description>&lt;p&gt;Copying is so ordinary in classical computing that we never think about it. Every assignment, every memory write, every &lt;code&gt;Ctrl+C&lt;/code&gt; duplicates a bit string perfectly and at will. Quantum mechanics flatly refuses to do the same for an unknown state. There is no machine, no clever circuit, no sequence of gates that takes an arbitrary qubit and hands you back two identical copies of it. This is the no-cloning theorem, and far from being a limitation we tolerate, it is the structural reason quantum key distribution is secure, the reason entanglement cannot be used to signal faster than light, and the reason quantum error correction had to be reinvented from scratch.&lt;/p&gt;

&lt;p&gt;The proof is short. It falls out of two properties we have already relied on throughout this series: linearity of quantum evolution, and unitarity. Below we prove it both ways, clear up the very common confusion about CNOT "copying" a qubit, walk through the consequences, and then watch a cloning attempt fail in Qiskit.&lt;/p&gt;

&lt;h2&gt;
  
  
  1 · What "cloning" would actually mean
&lt;/h2&gt;

&lt;p&gt;A cloning machine would be a single fixed unitary &lt;strong&gt;U&lt;/strong&gt; together with a standard blank register &lt;strong&gt;|e⟩&lt;/strong&gt;, such that for &lt;em&gt;every&lt;/em&gt; possible input state |ψ⟩ it produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;U ( |ψ⟩ ⊗ |e⟩ )  =  |ψ⟩ ⊗ |ψ⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three pieces of that statement deserve unpacking, because the whole theorem turns on them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What |e⟩ is, and what "blank" means.&lt;/strong&gt; The register |e⟩ is simply the second slot, the one that will end up holding the copy. We call it "blank" by analogy with an empty sheet of paper or an uninitialised memory cell: before the operation it carries no information whatsoever about the input |ψ⟩. The conventional choice is |0⟩, or |0...0⟩ when the copy needs several qubits, but |e⟩ does not have to be the zero vector specifically. Any fixed pure state works equally well for the theorem. The property that actually matters is not its literal value but that it is &lt;em&gt;independent of the unknown input&lt;/em&gt;. A register that already secretly equalled |ψ⟩ would not be blank, and you would not have copied anything, you would have been handed the answer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What "fixed" means, for both U and |e⟩.&lt;/strong&gt; Fixed means chosen in advance and identical on every run, never allowed to depend on which |ψ⟩ happens to come in. This is the condition that keeps the problem honest. If you were permitted to pick |e⟩ or U based on the input, you would first have to know what |ψ⟩ is, and at that point there is nothing left to clone: you could just prepare a second copy yourself. So the cloner gets one unitary and one starting register, and they must work for an arbitrary, unknown input. The claim of the theorem is that no such pair (U, |e⟩) exists.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why cloning a &lt;em&gt;known&lt;/em&gt; state is allowed, and how you do it.&lt;/strong&gt; The theorem forbids copying an &lt;em&gt;unknown&lt;/em&gt; arbitrary state. It says nothing about states you already understand, and there are two everyday ways such a state can be "known":&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;You know...&lt;/th&gt;
&lt;th&gt;How you get two copies&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;The preparation recipe (the amplitudes, or the circuit that builds it)&lt;/td&gt;
&lt;td&gt;Just run the preparation twice on two fresh |0⟩ qubits. You are re-preparing from a known description, not copying an unknown state.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;That the state is one of a known &lt;em&gt;orthogonal&lt;/em&gt; set&lt;/td&gt;
&lt;td&gt;Measure in the basis that distinguishes the set. Orthogonal states are eigenstates of that measurement, so they survive it undisturbed. Read off the label, then re-prepare as many copies as you like.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;As a concrete example of the first route, if you are told the state is |ψ⟩ = Ry(θ)|0⟩ for a known angle θ, you simply apply Ry(θ) to two separate qubits. No universal device is involved, and no rule is broken. The contradiction in the next two sections appears only when no such side information exists, that is, when the same machine must handle a continuum of unknown inputs at once.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The one-line distinction:&lt;/strong&gt; you can always re-prepare a state you know how to build, and you can copy states that act like classical labels. What you cannot do is build one fixed machine that duplicates an arbitrary, unknown state handed to you blind.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  2 · Proof I: linearity forbids it
&lt;/h2&gt;

&lt;p&gt;Assume, for contradiction, that a universal cloner U exists. Pick two arbitrary states |ψ⟩ and |φ⟩. By assumption U clones both of them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;U |ψ⟩|e⟩  =  |ψ⟩|ψ⟩
U |φ⟩|e⟩  =  |φ⟩|φ⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now feed the machine a superposition of the two inputs, |χ⟩ = (1/√2)(|ψ⟩ + |φ⟩). Quantum evolution is linear, so U acts term by term on the input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;U |χ⟩|e⟩  =  (1/√2) ( U|ψ⟩|e⟩ + U|φ⟩|e⟩ )
          =  (1/√2) ( |ψ⟩|ψ⟩ + |φ⟩|φ⟩ )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But if U is genuinely a cloner, then by definition it must also clone |χ⟩ itself, producing |χ⟩|χ⟩. Expanding that out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|χ⟩|χ⟩  =  (1/2) ( |ψ⟩ + |φ⟩ )( |ψ⟩ + |φ⟩ )
        =  (1/2) ( |ψ⟩|ψ⟩ + |ψ⟩|φ⟩ + |φ⟩|ψ⟩ + |φ⟩|φ⟩ )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two results disagree. Linearity gave us only the "diagonal" terms |ψ⟩|ψ⟩ and |φ⟩|φ⟩, whereas true cloning of |χ⟩ demands the cross terms |ψ⟩|φ⟩ and |φ⟩|ψ⟩ as well. They can only match if the cross terms vanish, which happens precisely when |ψ⟩ and |φ⟩ are identical or orthogonal. For general, non-orthogonal states the equality is impossible. The cloner cannot exist.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The contradiction is the same one that powers most quantum no-go results: a device defined by its action on a basis is forced, by linearity, into a behaviour on superpositions that contradicts the original specification.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  3 · Proof II: unitarity forbids it
&lt;/h2&gt;

&lt;p&gt;The linearity argument shows cloning fails for superpositions. A second proof, often considered the cleaner one, uses the fact that unitary operations preserve inner products. Suppose again that U clones two states:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;U |ψ⟩|e⟩  =  |ψ⟩|ψ⟩
U |φ⟩|e⟩  =  |φ⟩|φ⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The inner product is taken over the &lt;em&gt;full two-register states&lt;/em&gt; that U acts on, not over |ψ⟩ and |φ⟩ on their own. Label the two inputs and their images under U:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input A   = |ψ⟩|e⟩        Output UA  = |ψ⟩|ψ⟩
Input B   = |φ⟩|e⟩        Output UB  = |φ⟩|φ⟩

If U is unitary, then   ⟨A|B⟩  =  ⟨UA|UB⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That identity, ⟨A|B⟩ = ⟨UA|UB⟩, &lt;em&gt;is&lt;/em&gt; the definition of a unitary: it preserves inner products. U never acts on the inner product itself, which is only a number; it acts on the states, and unitarity says doing so cannot change their overlap. Now evaluate both sides, using the tensor-product factorisation ⟨a|⟨b| · |c⟩|d⟩ = ⟨a|c⟩ ⟨b|d⟩ and ⟨e|e⟩ = 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;⟨A|B⟩   = ⟨ψ|⟨e| · |φ⟩|e⟩  =  ⟨ψ|φ⟩ ⟨e|e⟩  =  ⟨ψ|φ⟩
⟨UA|UB⟩ = ⟨ψ|⟨ψ| · |φ⟩|φ⟩  =  ⟨ψ|φ⟩ ⟨ψ|φ⟩  =  ⟨ψ|φ⟩²

so   ⟨ψ|φ⟩  =  ⟨ψ|φ⟩²
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Write x = ⟨ψ|φ⟩. The condition x = x² rearranges to x(x − 1) = 0, whose only solutions are x = 0 or x = 1. In other words, cloning is consistent only when the two states are orthogonal (x = 0) or identical (x = 1). Any pair of distinct, non-orthogonal states, the generic case, breaks the equality. No universal cloner can exist.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;⟨ψ|φ⟩&lt;/th&gt;
&lt;th&gt;Relationship&lt;/th&gt;
&lt;th&gt;Cloneable?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;Orthogonal (a known basis set)&lt;/td&gt;
&lt;td&gt;Yes, this is just classical copying&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Identical (already known)&lt;/td&gt;
&lt;td&gt;Yes, trivially&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;anything else&lt;/td&gt;
&lt;td&gt;Distinct, non-orthogonal&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;No&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Both proofs converge on the same boundary. Orthogonal states carry distinguishable classical labels and can be copied; overlapping quantum states cannot.&lt;/p&gt;

&lt;h2&gt;
  
  
  4 · "But doesn't CNOT copy a qubit?"
&lt;/h2&gt;

&lt;p&gt;This is the single most common point of confusion, and it is worth resolving carefully. A CNOT with the input qubit as control and a fresh |0⟩ as target looks exactly like a copy operation. On computational basis states it behaves like one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CNOT |0⟩|0⟩  =  |0⟩|0⟩
CNOT |1⟩|0⟩  =  |1⟩|1⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So far it really is copying: the second qubit ends up matching the first. The trouble appears the moment the control is a superposition. Take |ψ⟩ = a|0⟩ + b|1⟩ as control and |0⟩ as target:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CNOT ( a|0⟩ + b|1⟩ )|0⟩  =  a|00⟩ + b|11⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare that with what a true clone would have produced, namely |ψ⟩|ψ⟩:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|ψ⟩|ψ⟩  =  a²|00⟩ + ab|01⟩ + ab|10⟩ + b²|11⟩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are different states. The CNOT output a|00⟩ + b|11⟩ is an &lt;strong&gt;entangled&lt;/strong&gt; pair, not two independent copies. If you discard the original and look at the "copy" on its own, you do not find |ψ⟩; you find a mixed state that has lost the phase relationship between a and b entirely. CNOT copies the value in the computational basis but destroys the superposition structure that made the state quantum in the first place. That is exactly the gap between copying classical information, which is always allowed, and cloning a quantum state, which is not.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Rule of thumb:&lt;/strong&gt; CNOT copies basis labels, not quantum states. The instant the input is in superposition, the "copy" is entanglement, not duplication.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  5 · Why this single theorem matters so much
&lt;/h2&gt;

&lt;p&gt;No-cloning is not a footnote. Three of the most important results in quantum information rest directly on it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quantum key distribution.&lt;/strong&gt; In BB84, Alice sends qubits encoded in randomly chosen bases. An eavesdropper, Eve, would love to intercept each qubit, keep a copy, and forward the original untouched so she can measure her copies later once the bases are announced. No-cloning makes that impossible. Eve cannot duplicate an unknown qubit, so she is forced to measure in transit, and measuring in the wrong basis disturbs the state and injects a detectable error rate. The security of the protocol is the no-cloning theorem wearing a different hat.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No faster-than-light signalling.&lt;/strong&gt; Entanglement correlates distant measurement outcomes, which has always tempted people into superluminal-communication schemes. Many of those schemes secretly assume Bob can clone his half of an entangled pair, make many copies, and read off the statistics to learn which basis Alice measured in. No-cloning closes that loophole and is one of the reasons quantum mechanics and relativity coexist without paradox.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quantum error correction.&lt;/strong&gt; Classical error correction leans on the simplest trick imaginable: copy the bit several times and take a majority vote. That is illegal in the quantum setting, because you cannot copy an unknown logical state. Quantum codes had to be built on a different principle, spreading logical information across many physical qubits using entanglement and measuring error syndromes without ever reading or duplicating the encoded state. The whole architecture of fault tolerance is shaped by the fact that the obvious classical fix is off the table.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A useful way to hold it in your head: no-cloning is what stops quantum information from behaving like classical information. Almost everything that makes quantum protocols both powerful and secure traces back to that one restriction.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  6 · Watching a clone fail in Qiskit
&lt;/h2&gt;

&lt;p&gt;The abstract proof is convincing, but it is satisfying to watch the failure happen numerically. We attempt the naive CNOT "clone" of the state |+⟩ = H|0⟩, then measure how badly it falls short by two yardsticks: fidelity against the intended |+⟩|+⟩, and the purity of the copy qubit on its own.&lt;/p&gt;

&lt;p&gt;Three terms in plain language:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fidelity&lt;/strong&gt; is a similarity score between two quantum states, from 0 to 1. Think of it as a match percentage: 1.0 means identical, 0 means completely unrelated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reduced state&lt;/strong&gt; is the honest description of one qubit when you ignore its partner. Picture two coins glued so they always land the same way: cover one and look at just the other, and that single coin looks like a plain 50/50 flip. The "match" information lived in the pair, not in either coin alone. Discarding the partner mathematically is called tracing it out.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purity&lt;/strong&gt; tells you whether a state is sharp and definite or a blurry random mixture. Purity 1 is a clean, definite state. For a single qubit the lowest value is 0.5, called maximally mixed, which is total randomness, the quantum version of a fair coin holding no information.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;qiskit&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;QuantumCircuit&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;qiskit.quantum_info&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Statevector&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;partial_trace&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state_fidelity&lt;/span&gt;

&lt;span class="n"&gt;qc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;        &lt;span class="c1"&gt;# prepare |+&amp;gt; on qubit 0 (the "original")
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="c1"&gt;# naive "cloning" attempt via CNOT
&lt;/span&gt;
&lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Statevector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# (|00&amp;gt; + |11&amp;gt;)/sqrt(2), a Bell state
&lt;/span&gt;
&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Statevector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_label&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;++&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# what we wanted: |+&amp;gt;|+&amp;gt;
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;state_fidelity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;    &lt;span class="c1"&gt;# 0.5
&lt;/span&gt;
&lt;span class="n"&gt;rho_copy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;partial_trace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;     &lt;span class="c1"&gt;# trace out the original
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rho_copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                     &lt;span class="c1"&gt;# I/2, maximally mixed
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rho_copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;purity&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;real&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;            &lt;span class="c1"&gt;# 0.5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running it gives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output state:           (√2/2)|00⟩ + (√2/2)|11⟩
Fidelity to |+⟩|+⟩:     0.5
Reduced state of copy:  [[0.5, 0], [0, 0.5]]
Purity of copy:         0.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every number tells the same story. The output is a maximally entangled Bell state, not the product |+⟩|+⟩ we were hoping for, and the fidelity to the intended clone is only 0.5. Trace out the original and the supposed "copy" is the maximally mixed state I/2, with purity 0.5 rather than 1. The copy retains no memory of the |+⟩ superposition at all; it is as good as a fair coin. The CNOT did precisely what the theorem says it must: it produced correlation, not duplication.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Try changing &lt;code&gt;qc.h(0)&lt;/code&gt; to any other single-qubit rotation, say &lt;code&gt;qc.ry(0.7, 0)&lt;/code&gt;. The fidelity stays stubbornly below 1 for every non-basis input, which is the no-cloning theorem reproduced one statevector at a time.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;em&gt;Part of the Quantum Series 2026, built with Qiskit 1.x. Originally published on &lt;a href="https://malcolmlow.com/2026/06/07/the-no-cloning-theorem-in-quantum-computing-why-you-cant-copy-a-qubit/" rel="noopener noreferrer"&gt;Techucation&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>quantum</category>
      <category>qiskit</category>
      <category>cryptography</category>
      <category>physics</category>
    </item>
    <item>
      <title>Publishing to WordPress with Claude and the WordPress MCP Connector</title>
      <dc:creator>Malcolm Low</dc:creator>
      <pubDate>Wed, 27 May 2026 14:39:03 +0000</pubDate>
      <link>https://dev.to/malcolmlow/publishing-to-wordpress-with-claude-and-the-wordpress-mcp-connector-711</link>
      <guid>https://dev.to/malcolmlow/publishing-to-wordpress-with-claude-and-the-wordpress-mcp-connector-711</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://malcolmlow.com/2026/05/26/publishing-to-wordpress-with-claude-and-the-wordpress-mcp-connector/" rel="noopener noreferrer"&gt;malcolmlow.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;Several posts on this blog — including &lt;a href="https://malcolmlow.com/2026/05/11/word-embeddings-explained-the-math-behind-ai-llms-and-chatbots/" rel="noopener noreferrer"&gt;Word Embeddings Explained&lt;/a&gt;, &lt;a href="https://malcolmlow.com/2026/05/08/singidbot-telegram-id-retrieval-bot-for-openclaw-topic-configuration/" rel="noopener noreferrer"&gt;SingIDBot&lt;/a&gt;, and the &lt;a href="https://malcolmlow.com/2026/05/04/connecting-telegram-bot-openclaw/" rel="noopener noreferrer"&gt;OpenClaw Telegram integration guide&lt;/a&gt; — were written, styled, and published entirely through Claude on claude.ai, using the WordPress MCP connector. This post documents exactly how that workflow operates, what problems arise, and how to resolve them.&lt;/p&gt;

&lt;p&gt;The combination of Claude's HTML generation capability and the WordPress MCP connector creates a surprisingly smooth authoring pipeline, provided you know the constraints WordPress imposes on custom HTML blocks. Those constraints are the non-obvious part, and they are addressed in detail below.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Prerequisites
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Requirement&lt;/th&gt;
&lt;th&gt;Details&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Claude account on claude.ai&lt;/td&gt;
&lt;td&gt;Free tier works; Pro gives longer contexts useful for large HTML posts.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WordPress.com site&lt;/td&gt;
&lt;td&gt;The MCP connector works with WordPress.com-hosted blogs. Self-hosted WordPress.org is not directly supported.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WordPress MCP connector enabled&lt;/td&gt;
&lt;td&gt;In claude.ai, go to &lt;strong&gt;Settings → Integrations&lt;/strong&gt; and enable the WordPress.com connector. Authenticate with your WordPress.com account.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  2. The Overall Workflow
&lt;/h2&gt;

&lt;p&gt;The end-to-end process has three stages. Claude handles all of them in a single conversation.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Stage&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;What happens&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Draft &amp;amp; Style&lt;/td&gt;
&lt;td&gt;Provide Claude with your content and request a WordPress HTML block with inline CSS only. No &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tags.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Review Output&lt;/td&gt;
&lt;td&gt;Preview the rendered HTML in claude.ai artifacts. Request edits until the post looks correct.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Publish via MCP&lt;/td&gt;
&lt;td&gt;Ask Claude to post using the WordPress connector. It checks categories and tags, creates any missing ones, then submits as a draft for your review.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Prompt for Stage 1:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Generate a WordPress post using a custom HTML block with inline CSS only. Do not use &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tags, &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags, or SVG."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Prompt for Stage 3:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Post this to myhlow.wordpress.com using the WordPress connector. Use appropriate categories and tags. Post as a draft first."&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  3. How the WordPress MCP Connector Works
&lt;/h2&gt;

&lt;p&gt;The MCP connector gives Claude direct access to your WordPress.com REST API. When you ask Claude to post, it performs these operations internally:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Loads the connector, resolving the &lt;code&gt;WordPress.com:wpcom-mcp-content-authoring&lt;/code&gt; tool.&lt;/li&gt;
&lt;li&gt;Lists existing categories using &lt;code&gt;categories.list&lt;/code&gt; to find IDs.&lt;/li&gt;
&lt;li&gt;Lists existing tags using &lt;code&gt;tags.list&lt;/code&gt; to find or create tags.&lt;/li&gt;
&lt;li&gt;Creates missing terms using &lt;code&gt;categories.create&lt;/code&gt; / &lt;code&gt;tags.create&lt;/code&gt; if needed.&lt;/li&gt;
&lt;li&gt;Creates the post using &lt;code&gt;posts.create&lt;/code&gt; with the HTML content, title, IDs, and status (&lt;code&gt;draft&lt;/code&gt; or &lt;code&gt;publish&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Returns the preview and edit URLs so you can open the draft in WordPress immediately.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Post content must be wrapped in a &lt;code&gt;wp:html&lt;/code&gt; block comment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- wp:html --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;...post content...&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- /wp:html --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  4. Problems Encountered — and How They Were Solved
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Problem 1: WordPress strips &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; blocks entirely
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happened:&lt;/strong&gt; Early posts used a &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag defining CSS classes. WordPress silently removed it on save, stripping all styling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; Every CSS rule must be a &lt;code&gt;style="..."&lt;/code&gt; attribute. Instruction: &lt;em&gt;"Use inline CSS only. Do not use &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tags."&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem 2: WordPress strips SVG elements
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happened:&lt;/strong&gt; Inline SVG circuit diagrams were stripped on save, leaving blank spaces.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; Replace SVG with HTML-native layout using CSS flexbox. Instruction: &lt;em&gt;"Do not use SVG."&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem 3: &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags are blocked
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happened:&lt;/strong&gt; JavaScript interactivity was silently discarded by WordPress content sanitisation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; Replace all interactivity with pure HTML/CSS alternatives.&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem 4: API parameter case sensitivity
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happened:&lt;/strong&gt; Passing &lt;code&gt;"order": "DESC"&lt;/code&gt; returned a validation error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; Always use lowercase: &lt;code&gt;"order": "desc"&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem 5: Duplicate categories and tags
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happened:&lt;/strong&gt; Claude created duplicate taxonomy terms without checking first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; Always call &lt;code&gt;categories.list&lt;/code&gt; and &lt;code&gt;tags.list&lt;/code&gt; before any creation step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem 6: &lt;code&gt;&amp;amp;nbsp;&lt;/code&gt; spacing and Unicode box-drawing characters break alignment
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happened:&lt;/strong&gt; Characters and &lt;code&gt;&amp;amp;nbsp;&lt;/code&gt; spacing that looked correct in claude.ai artifacts misaligned in WordPress because the theme font renders them at inconsistent widths.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; Replace character-based layout with CSS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single-wire gates: &lt;code&gt;display:flex; align-items:center&lt;/code&gt; rows with &lt;code&gt;inline-block&lt;/code&gt; wire spans and bordered gate boxes.&lt;/li&gt;
&lt;li&gt;Column vectors: &lt;code&gt;display:flex&lt;/code&gt; container with &lt;code&gt;border-left&lt;/code&gt;/&lt;code&gt;border-right&lt;/code&gt; bracket spans and &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; for rows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instruction: &lt;em&gt;"Never use &lt;code&gt;&amp;amp;nbsp;&lt;/code&gt; for alignment or Unicode box-drawing characters."&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem 7: Multi-wire circuits with vertical connectors require &lt;code&gt;position:absolute&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happened:&lt;/strong&gt; The CNOT gate required a vertical line connecting a control dot (●) to an XOR circle (⊕) on a separate wire. &lt;code&gt;border-top&lt;/code&gt;/&lt;code&gt;border-bottom&lt;/code&gt; on table cells produced horizontal bars; &lt;code&gt;rowspan="2"&lt;/code&gt; was visually correct but the theme's CSS overrode &lt;code&gt;&amp;lt;td&amp;gt;&lt;/code&gt; padding in ways inline styles couldn't fix.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; Three-part solution:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;&amp;lt;div style="display:table-cell"&amp;gt;&lt;/code&gt; instead of &lt;code&gt;&amp;lt;td&amp;gt;&lt;/code&gt; to bypass theme CSS selectors.&lt;/li&gt;
&lt;li&gt;Two separate &lt;code&gt;display:flex; height:28px&lt;/code&gt; rows in a &lt;code&gt;position:relative&lt;/code&gt; wrapper, with a &lt;code&gt;position:absolute; width:2px&lt;/code&gt; connector div.&lt;/li&gt;
&lt;li&gt;Asymmetric wire stubs: the control dot (12 px) needs 21 px stubs; the XOR circle (20 px) needs 17 px stubs — keeping both symbol centres at the same x-coordinate.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. Step-by-Step: Posting via Claude and WordPress MCP
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1 — Enable the WordPress Connector in claude.ai&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go to claude.ai → Settings → Integrations. Find the WordPress.com connector, click &lt;strong&gt;Connect&lt;/strong&gt;, and authorise with your WordPress.com account.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2 — Prompt Claude with the constraint set&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Generate a WordPress post as a custom HTML block.
Use inline CSS only — no &amp;lt;style&amp;gt; tags, no &amp;lt;script&amp;gt; tags, no SVG.
Never use &amp;amp;nbsp; for alignment or Unicode box-drawing characters.
Use display:flex and inline-block spans for diagrams and vectors.
For multi-wire circuits: use position:relative wrapper + position:absolute connector.
Match the styling of: [URL of a reference post]
Topic: [your content here]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3 — Review the artifact in claude.ai&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Verify layout, colours, and rendering. No &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags should appear.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4 — Trigger the MCP posting&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Post this to myhlow.wordpress.com using the WordPress connector.
Use appropriate categories and tags.
Status: draft
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Claude calls &lt;code&gt;categories.list&lt;/code&gt; and &lt;code&gt;tags.list&lt;/code&gt;, creates any missing terms, executes &lt;code&gt;posts.create&lt;/code&gt;, and returns the draft URLs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5 — Preview in WordPress and publish&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open the draft URL. If the Custom HTML block renders correctly, click Publish.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Installing the Workflow as a Reusable Skill
&lt;/h2&gt;

&lt;p&gt;All the constraints from this guide are packaged as a downloadable Claude Skill. Once installed, the skill auto-loads every time you start a WordPress publishing task.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Enable Code Execution and File Creation&lt;/strong&gt; — Settings → Capabilities → toggle on &lt;em&gt;Code Execution and File Creation&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open the Skills page&lt;/strong&gt; — &lt;a href="https://claude.ai/customize/skills" rel="noopener noreferrer"&gt;https://claude.ai/customize/skills&lt;/a&gt; (browser only, not the mobile app).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Upload the skill file&lt;/strong&gt; — "+" → "+ Create skill" → "Upload a skill" → select &lt;code&gt;wordpress-publish.skill&lt;/code&gt; → toggle it on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trigger in any new chat&lt;/strong&gt; — Say "publish to WordPress" and Claude loads all constraints automatically.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  7. Quick Reference: Dos and Don'ts
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Do&lt;/th&gt;
&lt;th&gt;Don't&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Use &lt;code&gt;style="..."&lt;/code&gt; on every element&lt;/td&gt;
&lt;td&gt;Use &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; blocks or CSS classes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use &lt;code&gt;display:flex&lt;/code&gt; + &lt;code&gt;inline-block&lt;/code&gt; for diagrams and vectors&lt;/td&gt;
&lt;td&gt;Use &lt;code&gt;&amp;amp;nbsp;&lt;/code&gt; or Unicode box-drawing characters for alignment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use &lt;code&gt;position:relative&lt;/code&gt; + &lt;code&gt;position:absolute&lt;/code&gt; connector for multi-wire circuits&lt;/td&gt;
&lt;td&gt;Use &lt;code&gt;border-top&lt;/code&gt;/&lt;code&gt;border-bottom&lt;/code&gt; on table cells to simulate vertical connectors&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use &lt;code&gt;&amp;lt;div style="display:table-cell"&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Rely on &lt;code&gt;&amp;lt;td&amp;gt;&lt;/code&gt; padding — theme CSS may override it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Wrap content in &lt;code&gt;&amp;lt;!-- wp:html --&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Use &lt;code&gt;&amp;lt;svg&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use lowercase &lt;code&gt;"order": "desc"&lt;/code&gt; in API params&lt;/td&gt;
&lt;td&gt;Use uppercase &lt;code&gt;"order": "DESC"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Post as draft first and preview in WordPress&lt;/td&gt;
&lt;td&gt;Publish directly without previewing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Let Claude auto-select categories and tags&lt;/td&gt;
&lt;td&gt;Create taxonomy terms without checking for existing ones&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Set table header styles on &lt;code&gt;&amp;lt;tr&amp;gt;&lt;/code&gt;, not &lt;code&gt;&amp;lt;th&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Apply background colours to &lt;code&gt;&amp;lt;th&amp;gt;&lt;/code&gt; elements&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Giving Claude the URL of an existing post and asking it to match the styling is the fastest way to maintain visual consistency across your blog. The Word Embeddings post and the SingIDBot guide were both created this way, borrowing section card layout, banner colours, and code block styles from earlier posts.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>claude</category>
      <category>wordpress</category>
      <category>webdev</category>
      <category>ai</category>
    </item>
    <item>
      <title>Say Goodbye to Finder. Meet Marta.</title>
      <dc:creator>Malcolm Low</dc:creator>
      <pubDate>Sat, 16 May 2026 03:29:43 +0000</pubDate>
      <link>https://dev.to/malcolmlow/say-goodbye-to-finder-meet-marta-4k0c</link>
      <guid>https://dev.to/malcolmlow/say-goodbye-to-finder-meet-marta-4k0c</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://malcolmlow.com/2026/03/11/say-goodbye-to-finder-meet-marta/" rel="noopener noreferrer"&gt;malcolmlow.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;macOS Finder has served Mac users faithfully since 1984 — but its age is showing. For anyone who regularly moves files between folders, manages projects with complex directory structures, or simply wants a more keyboard-friendly workflow, Finder's single-pane design quickly becomes a bottleneck.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Marta&lt;/strong&gt; is a modern, native macOS file manager that addresses every one of these frustrations. Best of all — it's free.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Marta?
&lt;/h2&gt;

&lt;p&gt;Marta is a dual-pane, keyboard-driven file manager built exclusively for macOS. Developed by Yan Zhulanow, it borrows the powerful two-panel paradigm from classic file managers like Total Commander and Midnight Commander — but wraps it in a clean, native macOS interface.&lt;/p&gt;

&lt;p&gt;It is highly customisable, supports themes, and has its own plugin and scripting ecosystem. But even out of the box, the difference is immediately noticeable.&lt;/p&gt;




&lt;h2&gt;
  
  
  How to Install Marta
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Option A — Direct Download (Recommended)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Head to the official Marta website and download the latest release:&lt;br&gt;
&lt;a href="https://marta.sh" rel="noopener noreferrer"&gt;marta.sh&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option B — Install via Homebrew&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--cask&lt;/span&gt; marta
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installation, optionally grant Full Disk Access for unrestricted folder navigation:&lt;br&gt;
&lt;strong&gt;System Settings → Privacy &amp;amp; Security → Full Disk Access → toggle Marta on&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Marta Beats Finder
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🪟 Dual-Pane Navigation — The Game Changer
&lt;/h3&gt;

&lt;p&gt;The single biggest advantage: a &lt;strong&gt;side-by-side dual-pane view&lt;/strong&gt;. Your screen is split into two independent file panels, each showing a different folder. You can see your source and destination simultaneously — copy or move files between them without ever losing your place or juggling multiple windows.&lt;/p&gt;

&lt;p&gt;For power users — developers, academics, content creators — this alone is worth the switch.&lt;/p&gt;

&lt;h3&gt;
  
  
  📁 Create New Folders in Seconds
&lt;/h3&gt;

&lt;p&gt;In Finder, creating a new folder means right-clicking through a context menu. In Marta, it's a single keyboard shortcut (&lt;code&gt;⌘ + ⇧ + N&lt;/code&gt;) — a new folder appears inline, ready to be named. Your workflow never breaks stride.&lt;/p&gt;

&lt;h3&gt;
  
  
  ⌨️ Fully Keyboard-Driven
&lt;/h3&gt;

&lt;p&gt;Navigate, open, rename, copy, move, and delete files without ever touching the mouse. Marta's keyboard-first design means experienced users can fly through file operations far faster than any GUI-only workflow allows.&lt;/p&gt;

&lt;h3&gt;
  
  
  🗃️ Tabs &amp;amp; Bookmarks
&lt;/h3&gt;

&lt;p&gt;Keep multiple folder locations open as tabs within each panel. Bookmark your most-used directories and jump to them instantly — particularly powerful for large project hierarchies.&lt;/p&gt;

&lt;h3&gt;
  
  
  🎨 Themeable &amp;amp; Configurable
&lt;/h3&gt;

&lt;p&gt;Marta supports custom themes and a powerful configuration file (&lt;code&gt;conf.marco&lt;/code&gt;). You can remap shortcuts, add plugins, and tailor the entire interface to your exact preferences.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Verdict
&lt;/h2&gt;

&lt;p&gt;Marta won't replace Finder for every macOS task — but as a daily driver for navigating, organising, and moving files, it is simply in a different league. The dual-pane view alone transforms how you work with files, and features like instant folder creation and keyboard navigation make it feel like a tool built for people who actually use their computer seriously.&lt;/p&gt;

&lt;p&gt;If you've ever felt frustrated waiting on Finder's slow animations, losing track of copy destinations, or clicking through five menus just to create a folder — &lt;strong&gt;give Marta five minutes. You won't go back.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://marta.sh" rel="noopener noreferrer"&gt;marta.sh →&lt;/a&gt;&lt;/p&gt;

</description>
      <category>macos</category>
      <category>productivity</category>
      <category>tools</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The Cost of Garbage in Quantum Computing: Why You Must Clean Up Junk Bits</title>
      <dc:creator>Malcolm Low</dc:creator>
      <pubDate>Sat, 16 May 2026 03:29:12 +0000</pubDate>
      <link>https://dev.to/malcolmlow/the-cost-of-garbage-in-quantum-computing-why-you-must-clean-up-junk-bits-47g5</link>
      <guid>https://dev.to/malcolmlow/the-cost-of-garbage-in-quantum-computing-why-you-must-clean-up-junk-bits-47g5</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://malcolmlow.com/2025/12/27/the-cost-of-garbage-why-we-must-clean-junk-bits/" rel="noopener noreferrer"&gt;malcolmlow.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In quantum computing, anything that "knows" what a qubit is doing acts as a &lt;strong&gt;Witness&lt;/strong&gt;. Leftover data (&lt;strong&gt;Junk Bits&lt;/strong&gt;) on an ancilla qubit act as witnesses, destroying the interference your algorithm needs to work.&lt;/p&gt;




&lt;h2&gt;
  
  
  1 . The Observer Effect
&lt;/h2&gt;

&lt;p&gt;Consider a simple circuit where a qubit passes through two Hadamard gates. Classically, two inversions cancel. Quantum mechanically, the same is true — &lt;em&gt;only if no information leaks out between them&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Case A: Ideal — No Junk&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;q0: |0&amp;gt; --H-----------H-- =&amp;gt; |0&amp;gt;  (100% probability)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two Hadamard gates cancel perfectly. Measurement always yields |0&amp;gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Case B: Broken — With Junk&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;q0: |0&amp;gt; --H----*-------H-- =&amp;gt; |0&amp;gt; or |1&amp;gt;  (50/50 noise)
               |
q1: |0&amp;gt; -------X---------- =&amp;gt; |junk&amp;gt;      (records q0's path)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ancilla qubit q1 becomes entangled with q0. It now "knows" which path q0 took — and that knowledge destroys the interference.&lt;/p&gt;




&lt;h2&gt;
  
  
  2 . Mathematical Working
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Ideal Case — interference works:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Start:    |0&amp;gt;
After H:  (1/sqrt2)(|0&amp;gt; + |1&amp;gt;)
After H:  (1/2)(|0&amp;gt; + |1&amp;gt; + |0&amp;gt; - |1&amp;gt;) = |0&amp;gt;   (cancel!)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The |1&amp;gt; terms cancel — constructive interference on |0&amp;gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Junk Case — interference destroyed:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Start:          |0&amp;gt;|0&amp;gt;
After H on q0:  (1/sqrt2)(|0&amp;gt; + |1&amp;gt;)|0&amp;gt;
After CX:       (1/sqrt2)(|00&amp;gt; + |11&amp;gt;)    &amp;lt;- entangled!
After H on q0:  (1/2)(|00&amp;gt; + |10&amp;gt; + |01&amp;gt; - |11&amp;gt;)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The terms cannot cancel because q1 differs in each: |00&amp;gt; vs |10&amp;gt; are orthogonal states. Interference is destroyed.&lt;/p&gt;




&lt;h2&gt;
  
  
  3 . The Solution: Uncomputation
&lt;/h2&gt;

&lt;p&gt;To restore interference, follow the &lt;strong&gt;Compute-Copy-Uncompute&lt;/strong&gt; pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;q_in : |x&amp;gt; --[COMPUTE]--+--[UNCOMPUTE]-- |x&amp;gt;    (unchanged)
                        |
q_anc: |0&amp;gt; -------------+--[UNCOMPUTE]-- |0&amp;gt;     (cleaned)
                        |
q_out: |0&amp;gt; -------------+--------------- |f(x)&amp;gt;  (result)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step by step:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Compute&lt;/strong&gt; — apply your function gates, writing the result onto q_anc&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Copy&lt;/strong&gt; — CNOT the result from q_anc into q_out&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Uncompute&lt;/strong&gt; — run the compute gates in reverse, resetting q_anc to |0&amp;gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With q_anc back to |0&amp;gt;, the witness is gone and interference is fully restored.&lt;/p&gt;




&lt;h2&gt;
  
  
  4 . Qiskit Implementation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;qiskit&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;transpile&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;qiskit_aer&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AerSimulator&lt;/span&gt;

&lt;span class="n"&gt;qc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# q0 = input, q1 = ancilla, q2 = output
&lt;/span&gt;
&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# COMPUTE:    entangle q0 -&amp;gt; q1 (creates junk)
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# COPY:       copy result q1 -&amp;gt; q2
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# UNCOMPUTE:  reverse compute, reset q1 -&amp;gt; |0&amp;gt;
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       &lt;span class="c1"&gt;# Interference fully restored
&lt;/span&gt;
&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measure_all&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;counts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AerSimulator&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;transpile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;AerSimulator&lt;/span&gt;&lt;span class="p"&gt;())).&lt;/span&gt;&lt;span class="nf"&gt;result&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;get_counts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Resulting state: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same circuit as a wire diagram (&lt;code&gt;@&lt;/code&gt; = control, &lt;code&gt;X&lt;/code&gt; = target):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;q0: |0&amp;gt; --H--@---------@--H-- M
             |         |
q1: |0&amp;gt; -----X----@----X----- M   (ancilla: |0&amp;gt; -&amp;gt; junk -&amp;gt; |0&amp;gt;)
                  |
q2: |0&amp;gt; ----------X---------- M   (output: holds f(x))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second &lt;code&gt;cx(0,1)&lt;/code&gt; exactly reverses the first, leaving q1 in |0&amp;gt;. With the witness removed, the final &lt;code&gt;h(0)&lt;/code&gt; performs clean interference and q0 deterministically outputs |0&amp;gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  5 . Why This Matters in Practice
&lt;/h2&gt;

&lt;p&gt;Uncomputation is not just a theoretical nicety. In real quantum algorithms:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Context&lt;/th&gt;
&lt;th&gt;Why it matters&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Grover's oracle&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Must leave ancilla qubits clean after marking the target, or subsequent diffusion steps decohere&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Arithmetic circuits&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Reversible adders/multipliers accumulate garbage at every intermediate step — all must be uncomputed before measurement&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Fault-tolerant circuits&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Strict qubit budgets; junk bits consume physical qubits that could otherwise be used for error correction&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Compute-Copy-Uncompute pattern is the standard solution across all three contexts.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Quantum Series 2025 · Built with Qiskit 1.x&lt;/em&gt;&lt;/p&gt;

</description>
      <category>quantumcomputing</category>
      <category>qiskit</category>
      <category>tutorial</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Quantum Computing: Grover's Algorithm — Inversion About the Mean</title>
      <dc:creator>Malcolm Low</dc:creator>
      <pubDate>Sat, 16 May 2026 03:18:38 +0000</pubDate>
      <link>https://dev.to/malcolmlow/quantum-computing-grovers-algorithm-inversion-about-the-mean-329o</link>
      <guid>https://dev.to/malcolmlow/quantum-computing-grovers-algorithm-inversion-about-the-mean-329o</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://malcolmlow.com/2026/03/28/quantum-computing-inversion-about-the-mean/" rel="noopener noreferrer"&gt;malcolmlow.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Grover's algorithm is a quantum search procedure that locates a marked item in an unsorted list of N items in O(√N) oracle queries — a quadratic speedup over any classical approach. For N = 8 (3 qubits), this means roughly ⌊π/4 × √8⌋ = &lt;strong&gt;2 optimal iterations&lt;/strong&gt; before the probability of measuring the target state peaks.&lt;/p&gt;

&lt;p&gt;This walkthrough tracks the exact amplitude of every basis state through each gate operation for the 3-qubit case, with target state &lt;strong&gt;|101⟩&lt;/strong&gt;. All arithmetic is shown so each step can be verified by hand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structure of each iteration (Grover operator G):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Oracle Uf&lt;/strong&gt; — Phase-flips the target state: |x⟩ → −|x⟩ if f(x) = 1, otherwise |x⟩ → |x⟩&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Diffusion operator D = H⊗n(2|0⟩⟨0| − I)H⊗n&lt;/strong&gt; — Reflects all amplitudes about their mean, amplifying the marked state at the expense of the others&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key insight:&lt;/strong&gt; The oracle introduces destructive interference at the target, which the diffusion operator converts into constructive interference by inverting amplitudes about their mean. Each iteration rotates the state vector by angle 2θ closer to the target, where sin(θ) = 1/√N.&lt;/p&gt;




&lt;h2&gt;
  
  
  Phase 0: Initialization
&lt;/h2&gt;

&lt;p&gt;Apply H⊗3 to |000⟩ to create a uniform superposition over all 8 basis states:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|ψinit⟩ = (1/√8)[ |000⟩ + |001⟩ + |010⟩ + |011⟩
                 + |100⟩ + |101⟩ + |110⟩ + |111⟩ ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every state has amplitude &lt;strong&gt;+1/√8 ≈ 0.3535&lt;/strong&gt; and probability &lt;strong&gt;12.5%&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Hadamard Reference (Standard Signs)
&lt;/h2&gt;

&lt;p&gt;Element (i, j) has sign (−1)^popcount(i AND j). This table is used in every Hadamard step below — each row shows how an input basis state distributes into all 8 output states.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          |000⟩ |001⟩ |010⟩ |011⟩ |100⟩ |101⟩ |110⟩ |111⟩
          ─────────────────────────────────────────────────
H|000⟩ →    +     +     +     +     +     +     +     +
H|001⟩ →    +     −     +     −     +     −     +     −
H|010⟩ →    +     +     −     −     +     +     −     −
H|011⟩ →    +     −     −     +     +     −     −     +
H|100⟩ →    +     +     +     +     −     −     −     −
H|101⟩ →    +     −     +     −     −     +     −     +
H|110⟩ →    +     +     −     −     −     −     +     +
H|111⟩ →    +     −     −     +     −     +     +     −
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Round 1: Oracle → Diffusion
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 3 — Oracle Uf&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The oracle recognises |101⟩ as the marked state and flips its amplitude from +1/√8 to −1/√8. All other amplitudes remain unchanged. The superposition is preserved — no measurement is made.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4.1 — First H (mapping to Hadamard basis)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each input state contributes ±1/8 to each output column via the sign table. The oracle-marked |101⟩ row is fully sign-inverted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                  |000⟩  |001⟩  |010⟩  |011⟩  |100⟩  |101⟩  |110⟩  |111⟩
                  ──────────────────────────────────────────────────────────
+H|000⟩  (+1/√8)  +1/8   +1/8   +1/8   +1/8   +1/8   +1/8   +1/8   +1/8
+H|001⟩  (+1/√8)  +1/8   -1/8   +1/8   -1/8   +1/8   -1/8   +1/8   -1/8
+H|010⟩  (+1/√8)  +1/8   +1/8   -1/8   -1/8   +1/8   +1/8   -1/8   -1/8
+H|011⟩  (+1/√8)  +1/8   -1/8   -1/8   +1/8   +1/8   -1/8   -1/8   +1/8
+H|100⟩  (+1/√8)  +1/8   +1/8   +1/8   +1/8   -1/8   -1/8   -1/8   -1/8
-H|101⟩  (-1/√8)  -1/8   +1/8   -1/8   +1/8   +1/8   -1/8   +1/8   -1/8  ← oracle row
+H|110⟩  (+1/√8)  +1/8   +1/8   -1/8   -1/8   -1/8   -1/8   +1/8   +1/8
+H|111⟩  (+1/√8)  +1/8   -1/8   -1/8   +1/8   -1/8   +1/8   +1/8   -1/8
          ───────────────────────────────────────────────────────────────────
Net 4.1           +6/8   +2/8   -2/8   +2/8   +2/8   -2/8   +2/8   -2/8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4.2 — Phase Flip (2|0⟩⟨0|−I)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Keep |000⟩ unchanged, negate all other states. This is the heart of inversion-about-the-mean.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         |000⟩  |001⟩  |010⟩  |011⟩  |100⟩  |101⟩  |110⟩  |111⟩
Post-Z:  +6/8   -2/8   +2/8   -2/8   -2/8   +2/8   -2/8   +2/8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4.3 — Second H (back to computational basis)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                  |000⟩  |001⟩  |010⟩  |011⟩  |100⟩  |101⟩  |110⟩  |111⟩
Net R1 (exact):  +4/8√8 +4/8√8 +4/8√8 +4/8√8 +4/8√8 +20/8√8 +4/8√8 +4/8√8
Net R1 (decimal):  0.177  0.177  0.177  0.177  0.177   0.884  0.177  0.177
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After Round 1, |101⟩ has been amplified from 0.354 to &lt;strong&gt;0.884&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Round 2: Oracle → Diffusion
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 5 — Oracle Uf&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The oracle flips |101⟩ from +20/8√8 to −20/8√8. The 7 non-target states remain at +4/8√8. This large asymmetry drives even stronger constructive interference in the diffusion step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6.1 — First H&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                      |000⟩   |001⟩   |010⟩   |011⟩   |100⟩   |101⟩   |110⟩   |111⟩
                      ──────────────────────────────────────────────────────────────────
+H|000⟩  (+4/8√8)    +4/64   +4/64   +4/64   +4/64   +4/64   +4/64   +4/64   +4/64
+H|001⟩  (+4/8√8)    +4/64   -4/64   +4/64   -4/64   +4/64   -4/64   +4/64   -4/64
+H|010⟩  (+4/8√8)    +4/64   +4/64   -4/64   -4/64   +4/64   +4/64   -4/64   -4/64
+H|011⟩  (+4/8√8)    +4/64   -4/64   -4/64   +4/64   +4/64   -4/64   -4/64   +4/64
+H|100⟩  (+4/8√8)    +4/64   +4/64   +4/64   +4/64   -4/64   -4/64   -4/64   -4/64
-H|101⟩  (-20/8√8)  -20/64  +20/64  -20/64  +20/64  +20/64  -20/64  +20/64  -20/64  ← oracle row
+H|110⟩  (+4/8√8)    +4/64   +4/64   -4/64   -4/64   -4/64   -4/64   +4/64   +4/64
+H|111⟩  (+4/8√8)    +4/64   -4/64   -4/64   +4/64   -4/64   +4/64   +4/64   -4/64
          ──────────────────────────────────────────────────────────────────────────────
Net 6.1              +8/64  +24/64  -24/64  +24/64  +24/64  -24/64  +24/64  -24/64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6.2 — Phase Flip&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         |000⟩   |001⟩   |010⟩   |011⟩   |100⟩   |101⟩   |110⟩   |111⟩
Post-Z:  +8/64  -24/64  +24/64  -24/64  -24/64  +24/64  -24/64  +24/64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6.3 — Second H&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                   |000⟩    |001⟩    |010⟩    |011⟩    |100⟩    |101⟩    |110⟩    |111⟩
Net R2 (exact):  -16/64√8 -16/64√8 -16/64√8 -16/64√8 -16/64√8 +176/64√8 -16/64√8 -16/64√8
Net R2 (decimal):  -0.088   -0.088   -0.088   -0.088   -0.088    +0.972   -0.088   -0.088
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Success Probability after Round 2: P(|101⟩) = |0.972|² ≈ 94.5%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Round 2 is the optimal stopping point&lt;/strong&gt; for 3-qubit Grover search — ⌊π/4 × √8⌋ = 2 iterations.&lt;/p&gt;




&lt;h2&gt;
  
  
  Round 3: The Overcooking Effect
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 7 — Oracle Uf&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With P(|101⟩) at 94.5%, one more iteration is one too many. The oracle flips |101⟩ from +176/64√8 to −176/64√8. The state vector has been rotated 2θ past its peak — a third diffusion step pushes it further away from the target, not closer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps 8.1–8.3 — Diffusion&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                   |000⟩    |001⟩    |010⟩    |011⟩    |100⟩    |101⟩    |110⟩    |111⟩
Net R3 (exact):  -448/512√8 (×7 non-target states)    +832/512√8 (target)
Net R3 (decimal):  -0.309   -0.309   -0.309   -0.309   -0.309    +0.575   -0.309   -0.309
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;P(|101⟩) = |0.575|² ≈ 33.0%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Summary: Amplitude Evolution Across Rounds
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Round   Target |101⟩   Non-target states   P(|101⟩)
──────────────────────────────────────────────────────
Init       +0.354          +0.354            12.5%
R1         +0.884          +0.177            78.1%
R2         +0.972          -0.088            94.5%  ← optimal stop
R3         +0.575          -0.309            33.0%  ← overcooked
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The state vector has rotated past the optimal angle. P(|101⟩) drops from 94.5% to &lt;strong&gt;33.0%&lt;/strong&gt; — a significant fall, but |101⟩ still has more than double the probability of any other state. The algorithm has not lost the answer; it has merely overshot the maximum.&lt;/p&gt;

&lt;p&gt;Importantly, the target amplitude is still positive (+0.575) — the vector has not crossed zero, it has simply overshot past the maximum. The result comes directly from the Born rule: P(|101⟩) = |amplitude|² = |+0.575|² ≈ 0.330.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Quantum Series 2026 · Built with Qiskit 1.x&lt;/em&gt;&lt;/p&gt;

</description>
      <category>quantumcomputing</category>
      <category>mathematics</category>
      <category>qiskit</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
