Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions demonstrations_v2/tutorial_qft_arithmetics/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

In this demo we will not focus on understanding how the QFT is built,
as we can find a great explanation in the
`PennyLane Codebook </codebook/08-quantum-fourier-transform/01-changing-perspectives/>`__. Instead, we will develop the
`PennyLane Codebook </codebook/quantum-fourier-transform/changing-perspectives/>`__. Instead, we will develop the
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this a dead link 😱

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, just a legacy way to do it; the links still work but redirect

intuition for how it works and how we can best take advantage of it.

Motivation
Expand Down Expand Up @@ -54,8 +54,8 @@
-----------------

To apply the QFT to basic arithmetic operations, our objective now is to learn how to add,
subtract and multiply numbers using quantum devices. As we are working with qubits,
—which, like bits, can take the
subtract and multiply numbers using quantum devices. As we are working with qubits—which,
like bits, can take the
values :math:`0` or :math:`1`—we will represent the numbers in binary. For the
purposes of this tutorial, we will assume that we are working only with
integers. Therefore, if we have :math:`n` qubits, we will be able to
Expand All @@ -71,7 +71,7 @@

.. math:: m= \sum_{i = 0}^{n-1}2^{n-1-i}q_i.

Note that :math:`\vert m \rangle` refers to the basic state
Note that :math:`\vert m \rangle` refers to the basis state
generated by the binary encoding of the number :math:`m.`
For instance, the natural number :math:`6`
is represented by the quantum state :math:`\vert 110\rangle,` since :math:`\vert 110 \rangle = 1 \cdot 2^2 + 1\cdot 2^1+0\cdot 2^0 = 6.`
Expand Down Expand Up @@ -286,12 +286,12 @@ def sum2(m, k, wires_m, wires_k, wires_solution):
#
# To understand the multiplication process, let's work with the binary decomposition of
# :math:`k:=\sum_{i=0}^{n-1}2^{n-i-1}k_i` and
# :math:`m:=\sum_{j=0}^{l-1}2^{l-j-1}m_i.` In this case, the product would
# :math:`m:=\sum_{j=0}^{l-1}2^{l-j-1}m_j.` In this case, the product would
# be:
#
# .. math:: k \cdot m = \sum_{i=0}^{n-1}\sum_{j = 0}^{l-1}m_ik_i (2^{n-i-1} \cdot 2^{l-j-1}).
# .. math:: k \cdot m = \sum_{i=0}^{n-1}\sum_{j = 0}^{l-1} k_i m_j (2^{n-i-1} \cdot 2^{l-j-1}).
#
# In other words, if :math:`k_i = 1` and :math:`m_i = 1,` we would add
# In other words, if :math:`k_i = 1` and :math:`m_j = 1,` we would add
# :math:`2^{n-i-1} \cdot 2^{l-j-1}` units to the counter, where :math:`n` and :math:`l`
# are the number of qubits with which we encode :math:`m` and :math:`k` respectively.
# Let's code to see how it works!
Expand Down Expand Up @@ -351,7 +351,7 @@ def mul(m, k):
# Let’s imagine now that we want just the opposite: to factor the
# number :math:`21` as a product of two terms. Is this something we could do
# using our previous reasoning? The answer is yes! We can make use of
# `Grover's algorithm <https://en.wikipedia.org/wiki/Grover%27s_algorithm>`_ to
# `Grover's algorithm </qml/demos/tutorial_grovers_algorithm>`__ to
# amplify the states whose product is the number we
# are looking for. All we would need is to construct the oracle :math:`U,` i.e., an
# operator such that
Expand Down Expand Up @@ -404,15 +404,15 @@ def factorization(n, wires_m, wires_k, wires_solution):


plt.bar(range(2 ** len(wires_m)), factorization(n, wires_m, wires_k, wires_solution))
plt.xlabel("Basic states")
plt.xlabel("Basis states")
plt.ylabel("Probability")
plt.show()

######################################################################
# By plotting the probabilities of obtaining each basic state we see that
# By plotting the probabilities of obtaining each basis state we see that
# prime factors have been amplified! Factorization via Grover’s algorithm
# does not achieve exponential improvement that
# `Shor's algorithm <https://en.wikipedia.org/wiki/Shor%27s_algorithm>`_ does, but we
# does not achieve the exponential improvement that
# `Shor's algorithm </codebook/shors-algorithm/shors-algorithm/>`__ does, but we
# can see that this construction is simple and a great example to
# illustrate basic arithmetic!
#
Expand All @@ -427,3 +427,9 @@ def factorization(n, wires_m, wires_k, wires_solution):
#
# Thomas G. Draper, "Addition on a Quantum Computer". `arXiv:quant-ph/0008033 <https://arxiv.org/abs/quant-ph/0008033>`__.
#






4 changes: 2 additions & 2 deletions demonstrations_v2/tutorial_qft_arithmetics/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"executable_stable": true,
"executable_latest": true,
"dateOfPublication": "2022-11-07T00:00:00+00:00",
"dateOfLastModification": "2025-10-15T00:00:00+00:00",
"dateOfLastModification": "2025-11-05T00:00:00+00:00",
"categories": [
"Getting Started",
"Algorithms",
Expand Down Expand Up @@ -43,4 +43,4 @@
"weight": 1.0
}
]
}
}