|
105 | 105 | "\n", |
106 | 106 | "import numpy as np\n", |
107 | 107 | "import sympy\n", |
108 | | - "from typing import Callable, Iterable, List, Optional, Sequence\n", |
| 108 | + "from typing import Callable, Iterable, Sequence\n", |
109 | 109 | "\n", |
110 | 110 | "import cirq" |
111 | 111 | ] |
|
169 | 169 | "\"\"\"Function to compute the elements of Z_n.\"\"\"\n", |
170 | 170 | "\n", |
171 | 171 | "\n", |
172 | | - "def multiplicative_group(n: int) -> List[int]:\n", |
| 172 | + "def multiplicative_group(n: int) -> list[int]:\n", |
173 | 173 | " \"\"\"Returns the multiplicative group modulo n.\n", |
174 | 174 | "\n", |
175 | 175 | " Args:\n", |
|
252 | 252 | "\"\"\"Function for classically computing the order of an element of Z_n.\"\"\"\n", |
253 | 253 | "\n", |
254 | 254 | "\n", |
255 | | - "def classical_order_finder(x: int, n: int) -> Optional[int]:\n", |
| 255 | + "def classical_order_finder(x: int, n: int) -> int | None:\n", |
256 | 256 | " \"\"\"Computes smallest positive r such that x**r mod n == 1.\n", |
257 | 257 | "\n", |
258 | 258 | " Args:\n", |
|
826 | 826 | }, |
827 | 827 | "outputs": [], |
828 | 828 | "source": [ |
829 | | - "def process_measurement(result: cirq.Result, x: int, n: int) -> Optional[int]:\n", |
| 829 | + "def process_measurement(result: cirq.Result, x: int, n: int) -> int | None:\n", |
830 | 830 | " \"\"\"Interprets the output of the order finding circuit.\n", |
831 | 831 | "\n", |
832 | 832 | " Specifically, it determines s/r such that exp(2πis/r) is an eigenvalue\n", |
|
935 | 935 | }, |
936 | 936 | "outputs": [], |
937 | 937 | "source": [ |
938 | | - "def quantum_order_finder(x: int, n: int) -> Optional[int]:\n", |
| 938 | + "def quantum_order_finder(x: int, n: int) -> int | None:\n", |
939 | 939 | " \"\"\"Computes smallest positive r such that x**r mod n == 1.\n", |
940 | 940 | "\n", |
941 | 941 | " Args:\n", |
|
1005 | 1005 | "\"\"\"Functions for factoring from start to finish.\"\"\"\n", |
1006 | 1006 | "\n", |
1007 | 1007 | "\n", |
1008 | | - "def find_factor_of_prime_power(n: int) -> Optional[int]:\n", |
| 1008 | + "def find_factor_of_prime_power(n: int) -> int | None:\n", |
1009 | 1009 | " \"\"\"Returns non-trivial factor of n if n is a prime power, else None.\"\"\"\n", |
1010 | 1010 | " for k in range(2, math.floor(math.log2(n)) + 1):\n", |
1011 | 1011 | " c = math.pow(n, 1 / k)\n", |
|
1020 | 1020 | "\n", |
1021 | 1021 | "def find_factor(\n", |
1022 | 1022 | " n: int,\n", |
1023 | | - " order_finder: Callable[[int, int], Optional[int]] = quantum_order_finder,\n", |
| 1023 | + " order_finder: Callable[[int, int], int | None] = quantum_order_finder,\n", |
1024 | 1024 | " max_attempts: int = 30,\n", |
1025 | | - ") -> Optional[int]:\n", |
| 1025 | + ") -> int | None:\n", |
1026 | 1026 | " \"\"\"Returns a non-trivial factor of composite integer n.\n", |
1027 | 1027 | "\n", |
1028 | 1028 | " Args:\n", |
|
0 commit comments