Skip to content

Commit 3fb7783

Browse files
AnnePicusNadav Ben Ami
authored andcommitted
Suggested English changes to Discrete Logarithm
1 parent 67063af commit 3fb7783

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

algorithms/algebraic/discrete_log/discrete_log.ipynb

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
"source": [
1616
"The Discrete Logarithm Problem [[1](#DiscreteLog)] was shown by Shor [[2](#Shor)] to be solved in a polynomial time using quantum computers, while the fastest classical algorithms take a superpolynomial time. The problem is at least as hard as the factoring problem. In fact, the hardness of the problem is the basis for the Diffie-Hellman [[3](#DiffieHellman)] protocol for key exchange. \n",
1717
"\n",
18-
"### Problem formulation\n",
18+
"## Formulating the Problem\n",
1919
"\n",
2020
"* **Input:** A cyclic group $G = \\langle g \\rangle$ with $g$ as a generator, and an element $x\\in G$.\n",
2121
"\n",
2222
"* **Promise:** There is a number $s$ such that $g^s = x$.\n",
2323
"\n",
24-
"* **Output:** $s$, the discrete logarithm: $s = \\log_gx$\n",
24+
"* **Output:** $s$, the discrete logarithm: $s = \\log_gx$.\n",
2525
"\n",
2626
"*** \n",
2727
"\n",
28-
"In Shor's implementation the order of $g$ is assumed to be known beforehand (for example using the order finding algorithm). We will also assume it in the demonstration. \n",
28+
"In Shor's implementation, the order of $g$ is assumed to be known beforehand (for example, using the order finding algorithm). We also assume it in the demonstration. \n",
2929
"\n",
30-
"The Discrete Log problem is a specific example for the Abelian Hidden Subgroup Problem [[4](#HSP)], for the case of an additive group, with the function:\n",
30+
"The Discrete Log problem is a specific example of the Abelian Hidden Subgroup Problem [[4](#HSP)] for the case of an additive group, with this function:\n",
3131
"$$\n",
3232
"f: \\mathbb{Z}_N \\times \\mathbb{Z}_N \\rightarrow G\n",
3333
"$$\n",
@@ -41,29 +41,29 @@
4141
"id": "8ab4be3d-dbd8-41d4-be9d-d025deebf713",
4242
"metadata": {},
4343
"source": [
44-
"## How to build the Algorithm with Classiq"
44+
"## Building the Algorithm with Classiq"
4545
]
4646
},
4747
{
4848
"cell_type": "markdown",
4949
"id": "b14cfda4-29fa-45e5-a59c-f4c798f09172",
5050
"metadata": {},
5151
"source": [
52-
"The heart of the algorithm's logic is the implementation of the function:\n",
52+
"The heart of the algorithm's logic is the implementation of the function\n",
5353
"$$\n",
54-
"|x_1\\rangle|x_2\\rangle|1\\rangle \\rightarrow |x_1\\rangle|x_2\\rangle|x^{x_1} g^{x_2}\\rangle \n",
54+
"|x_1\\rangle|x_2\\rangle|1\\rangle \\rightarrow |x_1\\rangle|x_2\\rangle|x^{x_1} g^{x_2}\\rangle. \n",
5555
"$$\n",
5656
"\n",
57-
"This is done using 2 applications of the modular exponentiation function, which was described in detail in the [Shor's Factoring Algorithm](https://github.com/Classiq/classiq-library/blob/main/algorithms/algebraic/shor/shor_modular_exponentiation.ipynb) notebook. So here we will just import it from the classiq's library.\n",
57+
"This is done using two applications of the modular exponentiation function, described in detail in the [Shor's Factoring Algorithm](https://github.com/Classiq/classiq-library/blob/main/algorithms/algebraic/shor/shor_modular_exponentiation.ipynb) notebook. So here we import it from the Classiq library.\n",
5858
"\n",
59-
"The function `modular_exp` accepts the following arguments:\n",
59+
"The `modular_exp` function accepts these arguments:\n",
6060
"- `n: CInt` - modulo number\n",
6161
"- `a: CInt` - base of the exponentiation\n",
62-
"- `x: QArray[QBit]` - unsigned integer to multiply be the exponentiation\n",
62+
"- `x: QArray[QBit]` - unsigned integer to multiply by the exponentiation\n",
6363
"- `power: QArray[QBit]`- power of the exponentiation\n",
6464
"\n",
65-
"So that the function implements:\n",
66-
"$|power\\rangle|x\\rangle \\rightarrow |power\\rangle|x \\cdot a ^ {power}\\mod n\\rangle$"
65+
"So the function implements \n",
66+
"$|power\\rangle|x\\rangle \\rightarrow |power\\rangle|x \\cdot a ^ {power}\\mod n\\rangle$."
6767
]
6868
},
6969
{
@@ -97,10 +97,10 @@
9797
"id": "23cf730e-17d2-4a76-b4d6-d39d4c9b865a",
9898
"metadata": {},
9999
"source": [
100-
"### The full algorithm:\n",
101-
"1. Prepare uniform superposition over the first 2 quantum variables `x1`, `x2`. Each variable should be with size $\\lceil \\log r\\rceil + \\log({1/{\\epsilon}})$. In the special case where $r$ is a power of 2, $\\log r$ is enough.\n",
102-
"3. Compute `discrete_log_oracle` on the `func_res` variable. `func_res` should be of size $\\lceil \\log N\\rceil$.\n",
103-
"4. Apply inverse Fourier transform `x1`, `x2`.\n",
100+
"### Full Algorithm\n",
101+
"1. Prepare uniform superposition over the first two quantum variables `x1`, `x2`. Each variable has size $\\lceil \\log r\\rceil + \\log({1/{\\epsilon}})$. In the special case where $r$ is a power of 2, $\\log r$ is enough.\n",
102+
"3. Compute `discrete_log_oracle` on the `func_res` variable. `func_res` is of size $\\lceil \\log N\\rceil$.\n",
103+
"4. Apply the inverse Fourier transform `x1`, `x2`.\n",
104104
"5. Measure."
105105
]
106106
},
@@ -142,14 +142,14 @@
142142
"id": "56b2c254-8894-4b05-9cf1-deded6ab15cc",
143143
"metadata": {},
144144
"source": [
145-
"After the inverse QFTs, we get in the variables (under the assumption of $r=2^m$ for some $m$):\n",
146-
"$$|\\psi\\rangle = \\sum_{\\nu\\in\\mathbb{Z}_r, \\delta\\in G}\\omega^{\\nu\\delta}|\\nu\\cdot log_gx\\rangle_{x_1}|\\nu\\rangle_{x_2}|\\delta>_{func\\_res}$$\n",
145+
"After the inverse QFTs (under the assumption of $r=2^m$ for some $m$), the variables become\n",
146+
"$$|\\psi\\rangle = \\sum_{\\nu\\in\\mathbb{Z}_r, \\delta\\in G}\\omega^{\\nu\\delta}|\\nu\\cdot log_gx\\rangle_{x_1}|\\nu\\rangle_{x_2}|\\delta>_{func\\_res}$$.\n",
147147
"\n",
148-
"For every $\\nu$ that has a mutplicative inverse in $\\mathbb{Z}_r$, we can extract $s=\\log_xg$ by multiplying the first variable result by its inverse.\n",
148+
"For every $\\nu$ that has a multiplicative inverse in $\\mathbb{Z}_r$, we can extract $s=\\log_xg$ by multiplying the first variable result by its inverse.\n",
149149
"\n",
150-
"In the case where $r$ is not a power of 2, we get in the variables and approximation of: |$\\log_g(x)\\cdot \\nu/ r\\rangle_{x_1} |\\nu / r\\rangle_{x_2}$. So we can use the continued fractions algorithm [[5](#ContinuedFraction)] to compute $\\nu/r$, then using the same technique to calculate $\\log_gx$.\n",
150+
"If $r$ is not a power of 2, the variables get an approximation of |$\\log_g(x)\\cdot \\nu/ r\\rangle_{x_1} |\\nu / r\\rangle_{x_2}$. So we can use the continued fractions algorithm [[5](#ContinuedFraction)] to compute $\\nu/r$, then use the same technique to calculate $\\log_gx$.\n",
151151
"\n",
152-
"*Note: Alternatively, one might implement the $QFT_{\\mathbb{Z}_r}$ over general $r$, and instead of the uniform superposition prepare the states: $\\frac{1}{\\sqrt{r}}\\sum_{x\\in\\mathbb{r}}|x\\rangle$ in `x1`, `x2`. Then again no continued fractions post-process is required.*"
152+
"*Note: Alternatively, you could implement the $QFT_{\\mathbb{Z}_r}$ over general $r$, and instead of the uniform superposition, prepare the states: $\\frac{1}{\\sqrt{r}}\\sum_{x\\in\\mathbb{r}}|x\\rangle$ in `x1`, `x2`. Then, again, no continued fractions postprocessing is required.*"
153153
]
154154
},
155155
{
@@ -178,9 +178,9 @@
178178
"id": "c8c1edc5-0271-48c6-ac7d-7bdc17598568",
179179
"metadata": {},
180180
"source": [
181-
"For this specific demonstration, we choose $G = \\mathbb{Z}_5^\\times$, with $g=3$ and $x=2$. Under this setting, $log_gx=3$.\n",
181+
"For this specific demonstration, we choose $G = \\mathbb{Z}_5^\\times$, with $g=3$ and $x=2$. With this setting, $log_gx=3$.\n",
182182
"\n",
183-
"We choose this specific example as the order of of the group $r=4$ is a power of $2$, and so we can get exactly the discrete logarithm, without continued-fractions post processing. In other cases, one has to use larger quantum variable for the exponents so the continued fractions post-processing will converge."
183+
"We choose this specific example because the order of the group $r=4$ is a power of $2$, so we can get the exact discrete logarithm without continued-fractions postprocessing. In other cases, we use a larger quantum variable for the exponents so the continued fractions postprocessing converges."
184184
]
185185
},
186186
{
@@ -248,10 +248,10 @@
248248
"id": "c405feed-408f-4d91-a22c-0b445b2ff6c2",
249249
"metadata": {},
250250
"source": [
251-
"Notice that `func_res` is uncorrelated to the other variables, and we get uniform distribution, as expected. \n",
251+
"Note that `func_res` is uncorrelated to the other variables, and we get uniform distribution, as expected. \n",
252252
"\n",
253253
"We take only the `x2` that are co-prime to $r=4$, so they have a multiplicative-inverse. Hence `x2=1,3` are the relevant results.\n",
254-
"So we get 2 relevant results (for all different $\\delta$s): $|1\\rangle|3\\rangle$, $|3\\rangle|1\\rangle$. All left to do to get the logarithm is to multiply `x1` by the inverse of `x2`:"
254+
"So we get two relevant results (for all different $\\delta$s): $|1\\rangle|3\\rangle$, $|3\\rangle|1\\rangle$. All that remains to get the logarithm is to multiply `x1` by the inverse of `x2`:"
255255
]
256256
},
257257
{
@@ -295,7 +295,7 @@
295295
"id": "a83324a1-202e-4589-b663-e4b0e631e680",
296296
"metadata": {},
297297
"source": [
298-
"Verify we got the correct discrete logarithm:"
298+
"Verify we received the correct discrete logarithm:"
299299
]
300300
},
301301
{
@@ -321,7 +321,7 @@
321321
"id": "3fd236be-032d-4513-806c-086a8623a40d",
322322
"metadata": {},
323323
"source": [
324-
"And indeed in both cases the same result, which is exactly the discrete logarithm: $\\log_32 \\mod 5 = 3$"
324+
"And, indeed, both cases give the same result, which is exactly the discrete logarithm: $\\log_32 \\mod 5 = 3$."
325325
]
326326
},
327327
{
@@ -337,9 +337,9 @@
337337
"id": "1702d0f8-bca1-4e00-bffd-4b8c0ec4ddcb",
338338
"metadata": {},
339339
"source": [
340-
"Here we take the case were the order is not a power of 2. In the circuit creation, we will need to change the state preparation. Instead of creating the entire uniform distribution on the `x1`, `x2` variables, we will load them with the uniform superposition of only the first `#ORDER` states.\n",
340+
"In this case the order is not a power of 2. During circuit creation, we change the state preparation: instead of creating the entire uniform distribution on the `x1`, `x2` variables, we load them with the uniform superposition of only the first `#ORDER` states.\n",
341341
"\n",
342-
"In order to do that we can use the library function `prepare_uniform_trimmed_state` which prepare such a state efficiently."
342+
"We do that using the `prepare_uniform_trimmed_state` library function, which efficiently prepares such a state."
343343
]
344344
},
345345
{
@@ -367,7 +367,7 @@
367367
") -> None:\n",
368368
" reg_len = ceiling(log(order, 2)) + 1\n",
369369
"\n",
370-
" # we define the variables with fraction places in order to ease the post-processing\n",
370+
" # we define the variables with fraction places to ease the postprocessing\n",
371371
" allocate_num(reg_len, False, reg_len, x1)\n",
372372
" allocate_num(reg_len, False, reg_len, x2)\n",
373373
"\n",
@@ -453,15 +453,15 @@
453453
"id": "89ea05c0-7939-42a3-8cdf-4e46989ce401",
454454
"metadata": {},
455455
"source": [
456-
"#### Post process"
456+
"#### Postprocessing"
457457
]
458458
},
459459
{
460460
"cell_type": "markdown",
461461
"id": "74e6acb6-43c0-41ad-a0dc-eac9c9f5f5cc",
462462
"metadata": {},
463463
"source": [
464-
"We now have additional step in post-process. We translate each result to the closest fraction with denominator which is the order:"
464+
"We now have an additional step in postprocessing. We translate each result to the closest fraction with a denominator, which is the order:"
465465
]
466466
},
467467
{
@@ -526,7 +526,7 @@
526526
"id": "e2e15760-1bbb-4d79-8499-d111a2009135",
527527
"metadata": {},
528528
"source": [
529-
"Now take a sample where `x2` is co-prime to the order, such that we can get the logarithm by multiplying `x1` by the modular inverse. If the the `x1`, `x2` registers are large enough, we are guaranteed to sample it with a good probability:"
529+
"Now, we take a sample where `x2` is co-prime to the order, such that we can get the logarithm by multiplying `x1` by the modular inverse. If the `x1`, `x2` registers are large enough, we are guaranteed to sample it with a good probability:"
530530
]
531531
},
532532
{
@@ -578,7 +578,7 @@
578578
"\n",
579579
"<a id='DiscreteLog'>[1]</a>: [Discrete Logarithm (Wikipedia)](https://en.wikipedia.org/wiki/Discrete_logarithm)\n",
580580
"\n",
581-
"<a id='Shor94'>[2]</a>: [Shor, Peter W. \"Algorithms for quantum computation: discrete logarithms and factoring.\" Proceedings 35th annual symposium on foundations of computer science. Ieee, 1994.](https://ieeexplore.ieee.org/abstract/document/365700)\n",
581+
"<a id='Shor94'>[2]</a>: [Shor, Peter W. \"Algorithms for quantum computation: discrete logarithms and factoring.\" Proceedings 35th annual symposium on foundations of computer science. IEEE, 1994.](https://ieeexplore.ieee.org/abstract/document/365700)\n",
582582
"\n",
583583
"<a id='DiffieHellman'>[3]</a>: [Diffie-Hellman Key Exchange (Wikipedia)](https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange)\n",
584584
"\n",

0 commit comments

Comments
 (0)