Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring the names of the variable for clarity and consistency in discrete_log.ipynb #47

Merged
merged 2 commits into from
Jun 6, 2024
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
36 changes: 18 additions & 18 deletions algorithms/algebraic/discrete_log/discrete_log.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 5,
"id": "2bbc4aa3-8f61-433d-a1cd-c58df445a2fd",
"metadata": {
"execution": {
Expand All @@ -92,20 +92,20 @@
"\n",
"@qfunc\n",
"def discrete_log_oracle(\n",
" g: CInt,\n",
" x: CInt,\n",
" N: CInt,\n",
" g_generator: CInt,\n",
" x_element: CInt,\n",
" N_modulus: CInt,\n",
" order: CInt,\n",
" x1: QArray[QBit],\n",
" x2: QArray[QBit],\n",
" func_res: Output[QArray[QBit]],\n",
") -> None:\n",
"\n",
" allocate(ceiling(log(N, 2)), func_res)\n",
" allocate(ceiling(log(N_modulus, 2)), func_res)\n",
"\n",
" inplace_prepare_int(1, func_res)\n",
" modular_exp(N, x, func_res, x1)\n",
" modular_exp(N, g, func_res, x2)"
" modular_exp(N_modulus, x_element, func_res, x1)\n",
" modular_exp(N_modulus, g_generator, func_res, x2)"
]
},
{
Expand All @@ -122,7 +122,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 6,
"id": "d7fb63ac-023d-40ac-9395-13c1274d446f",
"metadata": {
"execution": {
Expand All @@ -140,9 +140,9 @@
"\n",
"@qfunc\n",
"def discrete_log(\n",
" g: CInt,\n",
" x: CInt,\n",
" N: CInt,\n",
" g_generator: CInt,\n",
" x_element: CInt,\n",
" N_modulus: CInt,\n",
" order: CInt,\n",
" x1: Output[QArray[QBit]],\n",
" x2: Output[QArray[QBit]],\n",
Expand All @@ -155,7 +155,7 @@
" hadamard_transform(x1)\n",
" hadamard_transform(x2)\n",
"\n",
" discrete_log_oracle(g, x, N, order, x1, x2, func_res)\n",
" discrete_log_oracle(g_generator, x_element, N_modulus, order, x1, x2, func_res)\n",
"\n",
" invert(lambda: qft(x1))\n",
" invert(lambda: qft(x2))"
Expand Down Expand Up @@ -209,7 +209,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 7,
"id": "8ef24bb4-b063-42d6-a5ea-ddcd5310ae13",
"metadata": {
"execution": {
Expand All @@ -224,8 +224,8 @@
"from classiq import Constraints, create_model\n",
"\n",
"MODULU_NUM = 5\n",
"G = 3\n",
"X = 2\n",
"G_GENERATOR = 3\n",
"X_LOGARITHM = 2\n",
"ORDER = MODULU_NUM - 1 # as 5 is prime\n",
"\n",
"\n",
Expand All @@ -235,12 +235,12 @@
" x2: Output[QNum],\n",
" func_res: Output[QNum],\n",
") -> None:\n",
" discrete_log(G, X, MODULU_NUM, ORDER, x1, x2, func_res)"
" discrete_log(G_GENERATOR, X_LOGARITHM, MODULU_NUM, ORDER, x1, x2, func_res)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 8,
"id": "8e9d0b08-f3f8-4e95-a468-bfeec010d97c",
"metadata": {
"execution": {
Expand Down Expand Up @@ -272,7 +272,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "0aef2760-aa9a-4710-8c60-08333a0a9b0b",
"metadata": {
"execution": {
Expand Down
13 changes: 7 additions & 6 deletions algorithms/algebraic/discrete_log/discrete_log.qmod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
qfunc discrete_log_oracle<g: int, x: int, N: int, order: int>(x1: qbit[], x2: qbit[], output func_res: qbit[]) {
allocate<ceiling(log(N, 2))>(func_res);
qfunc discrete_log_oracle<g_generator: int, x_element: int, N_modulus: int, order: int>(x1: qbit[], x2: qbit[], output func_res: qbit[]) {
allocate<ceiling(log(N_modulus, 2))>(func_res);
inplace_prepare_int<1>(func_res);
modular_exp<N, x>(func_res, x1);
modular_exp<N, g>(func_res, x2);
modular_exp<N_modulus, x_element>(func_res, x1);
modular_exp<N_modulus, g_generator>(func_res, x2);
}

qfunc discrete_log<g: int, x: int, N: int, order: int>(output x1: qbit[], output x2: qbit[], output func_res: qbit[]) {
qfunc discrete_log<g_generator: int, x_element: int, N_modulus: int, order: int>(output x1: qbit[], output x2: qbit[], output func_res: qbit[]) {
allocate<ceiling(log(order, 2))>(x1);
allocate<ceiling(log(order, 2))>(x2);
hadamard_transform(x1);
hadamard_transform(x2);
discrete_log_oracle<g, x, N, order>(x1, x2, func_res);
discrete_log_oracle<g_generator, x_element, N_modulus, order>(x1, x2, func_res);
invert {
qft(x1);
}
Expand All @@ -22,3 +22,4 @@ qfunc discrete_log<g: int, x: int, N: int, order: int>(output x1: qbit[], output
qfunc main(output x1: qnum, output x2: qnum, output func_res: qnum) {
discrete_log<3, 2, 5, 4>(x1, x2, func_res);
}