From 46ef7bebb986e3b47a8f00f32f7a3adc23a3a373 Mon Sep 17 00:00:00 2001 From: mhostetter Date: Sun, 11 Sep 2022 10:43:24 -0400 Subject: [PATCH] Minor modification to `ValueError` messages --- src/galois/_codes/_bch.py | 12 +++---- src/galois/_codes/_linear.py | 4 +-- src/galois/_codes/_reed_solomon.py | 12 +++---- src/galois/_domains/_array.py | 10 +++--- src/galois/_domains/_linalg.py | 20 ++++++------ src/galois/_fields/_array.py | 14 ++++----- src/galois/_fields/_factory.py | 24 +++++++------- src/galois/_fields/_primitive_element.py | 12 +++---- src/galois/_lfsr.py | 8 ++--- src/galois/_math.py | 10 +++--- src/galois/_modular.py | 16 +++++----- src/galois/_ntt.py | 21 ++++--------- src/galois/_options.py | 2 +- src/galois/_polymorphic.py | 10 +++--- src/galois/_polys/_functions.py | 10 +++--- src/galois/_polys/_irreducible.py | 10 +++--- src/galois/_polys/_poly.py | 38 +++++++++++----------- src/galois/_polys/_primitive.py | 18 +++++------ src/galois/_prime.py | 40 ++++++++++++------------ 19 files changed, 141 insertions(+), 150 deletions(-) diff --git a/src/galois/_codes/_bch.py b/src/galois/_codes/_bch.py index 1868b0182..8e765fce4 100644 --- a/src/galois/_codes/_bch.py +++ b/src/galois/_codes/_bch.py @@ -36,9 +36,9 @@ def _check_and_compute_field( p, m = factors(n + 1) if not (len(p) == 1 and p[0] == 2): - raise ValueError(f"Argument `n` must have value `2^m - 1` for some positive m, not {n}.") + raise ValueError(f"Argument 'n' must equal 2^m - 1 for some positive m, not {n}.") if not c >= 1: - raise ValueError(f"Argument `c` must be at least 1, not {c}.") + raise ValueError(f"Argument 'c' must be at least 1, not {c}.") p, m = p[0], m[0] if primitive_poly is None: @@ -93,7 +93,7 @@ def bch_valid_codes(n: int, t_min: int = 1) -> list[tuple[int, int, int]]: verify_isinstance(n, int) verify_isinstance(t_min, int) if not t_min >= 1: - raise ValueError(f"Argument `t_min` must be at least 1, not {t_min}.") + raise ValueError(f"Argument 't_min' must be at least 1, not {t_min}.") GF = _check_and_compute_field(n, 0, 1, None, None) # NOTE: k isn't needed for generating the field alpha = GF.primitive_element @@ -399,13 +399,13 @@ def encode(self, message: ArrayLike, parity_only: bool = False) -> GF2: """ message = GF2(message) # This performs type/value checking if parity_only and not self.is_systematic: - raise ValueError("Argument `parity_only=True` only applies to systematic codes.") + raise ValueError("Argument 'parity_only=True' only applies to systematic codes.") if self.is_systematic: if not message.shape[-1] <= self.k: - raise ValueError(f"For a systematic code, argument `message` must be a 1-D or 2-D array with last dimension less than or equal to {self.k}, not shape {message.shape}.") + raise ValueError(f"For a systematic code, argument 'message' must be a 1-D or 2-D array with last dimension less than or equal to {self.k}, not shape {message.shape}.") else: if not message.shape[-1] == self.k: - raise ValueError(f"For a non-systematic code, argument `message` must be a 1-D or 2-D array with last dimension equal to {self.k}, not shape {message.shape}.") + raise ValueError(f"For a non-systematic code, argument 'message' must be a 1-D or 2-D array with last dimension equal to {self.k}, not shape {message.shape}.") ks = message.shape[-1] # The number of input message bits (could be less than self.k for shortened codes) diff --git a/src/galois/_codes/_linear.py b/src/galois/_codes/_linear.py index a7569da83..271976cd1 100644 --- a/src/galois/_codes/_linear.py +++ b/src/galois/_codes/_linear.py @@ -43,7 +43,7 @@ def generator_to_parity_check_matrix(G: FieldArray) -> FieldArray: field = type(G) k, n = G.shape if not np.array_equal(G[:,0:k], np.eye(k)): - raise ValueError("Argument `G` must be in systematic form [I | P].") + raise ValueError("Argument 'G' must be in systematic form [I | P].") P = G[:, k:] I = field.Identity(n-k) @@ -88,7 +88,7 @@ def parity_check_to_generator_matrix(H: FieldArray) -> FieldArray: n_k, n = H.shape k = n - n_k if not np.array_equal(H[:,k:], np.eye(n - k)): - raise ValueError("Argument `H` must be in systematic form [-P^T | I].") + raise ValueError("Argument 'H' must be in systematic form [-P^T | I].") P = -H[:, 0:k].T I = field.Identity(k) diff --git a/src/galois/_codes/_reed_solomon.py b/src/galois/_codes/_reed_solomon.py index d2a310dfd..d3d04a2d0 100644 --- a/src/galois/_codes/_reed_solomon.py +++ b/src/galois/_codes/_reed_solomon.py @@ -110,12 +110,12 @@ def __init__( verify_isinstance(systematic, bool) if not (n - k) % 2 == 0: - raise ValueError("Arguments `n - k` must be even.") + raise ValueError("Arguments 'n - k' must be even.") p, m = factors(n + 1) if not (len(p) == 1 and len(m) == 1): - raise ValueError(f"Argument `n` must have value `q - 1` for a prime power `q`, not {n}.") + raise ValueError(f"Argument 'n' must equal q - 1 for a prime power q, not {n}.") if not c >= 1: - raise ValueError(f"Argument `c` must be at least 1, not {c}.") + raise ValueError(f"Argument 'c' must be at least 1, not {c}.") p, m = p[0], m[0] if primitive_poly is None and m > 1: @@ -286,13 +286,13 @@ def encode(self, message: ArrayLike, parity_only: bool = False) -> FieldArray: """ message = self.field(message) # This performs type/value checking if parity_only and not self.is_systematic: - raise ValueError("Argument `parity_only=True` only applies to systematic codes.") + raise ValueError("Argument 'parity_only=True' only applies to systematic codes.") if self.is_systematic: if not message.shape[-1] <= self.k: - raise ValueError(f"For a systematic code, argument `message` must be a 1-D or 2-D array with last dimension less than or equal to {self.k}, not shape {message.shape}.") + raise ValueError(f"For a systematic code, argument 'message' must be a 1-D or 2-D array with last dimension less than or equal to {self.k}, not shape {message.shape}.") else: if not message.shape[-1] == self.k: - raise ValueError(f"For a non-systematic code, argument `message` must be a 1-D or 2-D array with last dimension equal to {self.k}, not shape {message.shape}.") + raise ValueError(f"For a non-systematic code, argument 'message' must be a 1-D or 2-D array with last dimension equal to {self.k}, not shape {message.shape}.") ks = message.shape[-1] # The number of input message symbols (could be less than self.k for shortened codes) diff --git a/src/galois/_domains/_array.py b/src/galois/_domains/_array.py index 875ad842d..017964228 100644 --- a/src/galois/_domains/_array.py +++ b/src/galois/_domains/_array.py @@ -223,9 +223,9 @@ def Range( dtype = cls._get_dtype(dtype) if not 0 <= start <= cls.order: - raise ValueError(f"Argument `start` must be within the field's order {cls.order}, not {start}.") + raise ValueError(f"Argument 'start' must be within the field's order {cls.order}, not {start}.") if not 0 <= stop <= cls.order: - raise ValueError(f"Argument `stop` must be within the field's order {cls.order}, not {stop}.") + raise ValueError(f"Argument 'stop' must be within the field's order {cls.order}, not {stop}.") array = np.arange(start, stop, step=step, dtype=dtype) @@ -351,10 +351,10 @@ def compile(cls, mode: Literal["auto", "jit-lookup", "jit-calculate", "python-ca """ verify_isinstance(mode, str) if not mode in ["auto", "jit-lookup", "jit-calculate", "python-calculate"]: - raise ValueError(f"Argument `mode` must be in ['auto', 'jit-lookup', 'jit-calculate', 'python-calculate'], not {mode!r}.") + raise ValueError(f"Argument 'mode' must be in ['auto', 'jit-lookup', 'jit-calculate', 'python-calculate'], not {mode!r}.") mode = cls.default_ufunc_mode if mode == "auto" else mode if mode not in cls.ufunc_modes: - raise ValueError(f"Argument `mode` must be in {cls.ufunc_modes} for {cls._name}, not {mode!r}.") + raise ValueError(f"Argument 'mode' must be in {cls.ufunc_modes} for {cls._name}, not {mode!r}.") if mode == cls.ufunc_mode: # Don't need to rebuild these ufuncs @@ -456,7 +456,7 @@ def display(cls, mode: Literal["int", "poly", "power"] = "int") -> Generator[Non """ verify_isinstance(mode, str, optional=True) if mode not in ["int", "poly", "power"]: - raise ValueError(f"Argument `mode` must be in ['int', 'poly', 'power'], not {mode!r}.") + raise ValueError(f"Argument 'mode' must be in ['int', 'poly', 'power'], not {mode!r}.") prev_mode = cls.display_mode cls._display_mode = mode # Set the new display mode diff --git a/src/galois/_domains/_linalg.py b/src/galois/_domains/_linalg.py index 9ae068629..ed7f70b00 100644 --- a/src/galois/_domains/_linalg.py +++ b/src/galois/_domains/_linalg.py @@ -287,7 +287,7 @@ class lu_decompose_jit(Function): def __call__(self, A: Array) -> tuple[Array, Array]: verify_isinstance(A, self.field) if not A.ndim == 2: - raise ValueError(f"Argument `A` must be a 2-D matrix, not have shape {A.shape}.") + raise ValueError(f"Argument 'A' must be a 2-D matrix, not have shape {A.shape}.") n = A.shape[0] Ai = A.copy() @@ -300,7 +300,7 @@ def __call__(self, A: Array) -> tuple[Array, Array]: L[i,i] = 1 continue else: - raise ValueError("The LU decomposition of `A` does not exist. Use the LUP decomposition instead.") + raise ValueError("The LU decomposition of 'A' does not exist. Use the LUP decomposition instead.") l = Ai[i+1:,i] / Ai[i,i] Ai[i+1:,:] -= np.multiply.outer(l, Ai[i,:]) @@ -319,7 +319,7 @@ class plu_decompose_jit(Function): def __call__(self, A: Array) -> tuple[Array, Array, Array, int]: verify_isinstance(A, self.field) if not A.ndim == 2: - raise ValueError(f"Argument `A` must be a 2-D matrix, not have shape {A.shape}.") + raise ValueError(f"Argument 'A' must be a 2-D matrix, not have shape {A.shape}.") n = A.shape[0] Ai = A.copy() @@ -365,7 +365,7 @@ class triangular_det_jit(Function): def __call__(self, A: Array) -> Array: verify_isinstance(A, self.field) if not (A.ndim == 2 and A.shape[0] == A.shape[1]): - raise np.linalg.LinAlgError(f"Argument `A` must be square, not {A.shape}.") + raise np.linalg.LinAlgError(f"Argument 'A' must be square, not {A.shape}.") idxs = np.arange(0, A.shape[0]) return np.multiply.reduce(A[idxs,idxs]) @@ -378,7 +378,7 @@ class det_jit(Function): def __call__(self, A: Array) -> Array: verify_isinstance(A, self.field) if not (A.ndim == 2 and A.shape[0] == A.shape[1]): - raise np.linalg.LinAlgError(f"Argument `A` must be square, not {A.shape}.") + raise np.linalg.LinAlgError(f"Argument 'A' must be square, not {A.shape}.") n = A.shape[0] @@ -419,7 +419,7 @@ class inv_jit(Function): def __call__(self, A: Array) -> Array: verify_isinstance(A, self.field) if not (A.ndim == 2 and A.shape[0] == A.shape[1]): - raise np.linalg.LinAlgError(f"Argument `A` must be square, not {A.shape}.") + raise np.linalg.LinAlgError(f"Argument 'A' must be square, not {A.shape}.") n = A.shape[0] I = self.field.Identity(n, dtype=A.dtype) @@ -433,7 +433,7 @@ def __call__(self, A: Array) -> Array: # The rank is the number of non-zero rows of the row reduced echelon form rank = np.sum(~np.all(AI_rre[:,0:n] == 0, axis=1)) if not rank == n: - raise np.linalg.LinAlgError(f"Argument `A` is singular and not invertible because it does not have full rank of {n}, but rank of {rank}.") + raise np.linalg.LinAlgError(f"Argument 'A' is singular and not invertible because it does not have full rank of {n}, but rank of {rank}.") A_inv = AI_rre[:,-n:] @@ -449,11 +449,11 @@ def __call__(self, A: Array, b: Array) -> Array: verify_isinstance(A, self.field) verify_isinstance(b, self.field) if not (A.ndim == 2 and A.shape[0] == A.shape[1]): - raise np.linalg.LinAlgError(f"Argument `A` must be square, not {A.shape}.") + raise np.linalg.LinAlgError(f"Argument 'A' must be square, not {A.shape}.") if not b.ndim in [1, 2]: - raise np.linalg.LinAlgError(f"Argument `b` must have dimension equal to A or one less, not {b.ndim}.") + raise np.linalg.LinAlgError(f"Argument 'b' must have dimension equal to 'A' or one less, not {b.ndim}.") if not A.shape[-1] == b.shape[0]: - raise np.linalg.LinAlgError(f"The last dimension of `A` must equal the first dimension of `b`, not {A.shape} and {b.shape}.") + raise np.linalg.LinAlgError(f"The last dimension of 'A' must equal the first dimension of 'b', not {A.shape} and {b.shape}.") A_inv = inv_jit(self.field)(A) x = A_inv @ b diff --git a/src/galois/_fields/_array.py b/src/galois/_fields/_array.py index 9d10edcb6..6fecbde4c 100644 --- a/src/galois/_fields/_array.py +++ b/src/galois/_fields/_array.py @@ -332,14 +332,14 @@ def Vandermonde(cls, element: ElementLike, rows: int, cols: int, dtype: DTypeLik verify_isinstance(rows, int) verify_isinstance(cols, int) if not rows > 0: - raise ValueError(f"Argument `rows` must be non-negative, not {rows}.") + raise ValueError(f"Argument 'rows' must be non-negative, not {rows}.") if not cols > 0: - raise ValueError(f"Argument `cols` must be non-negative, not {cols}.") + raise ValueError(f"Argument 'cols' must be non-negative, not {cols}.") dtype = cls._get_dtype(dtype) element = cls(element, dtype=dtype) if not element.ndim == 0: - raise ValueError(f"Argument `element` must be element scalar, not {element.ndim}-D.") + raise ValueError(f"Argument 'element' must be element scalar, not {element.ndim}-D.") v = element ** np.arange(0, rows) V = np.power.outer(v, np.arange(0, cols)) @@ -455,7 +455,7 @@ def repr_table(cls, element: ElementLike | None = None, sort: Literal["power", " GF("x^2").multiplicative_order() """ if sort not in ["power", "poly", "vector", "int"]: - raise ValueError(f"Argument `sort` must be in ['power', 'poly', 'vector', 'int'], not {sort!r}.") + raise ValueError(f"Argument 'sort' must be in ['power', 'poly', 'vector', 'int'], not {sort!r}.") if element is None: element = cls.primitive_element @@ -582,7 +582,7 @@ def arithmetic_table( GF.display() """ if not operation in ["+", "-", "*", "/"]: - raise ValueError(f"Argument `operation` must be in ['+', '-', '*', '/'], not {operation!r}.") + raise ValueError(f"Argument 'operation' must be in ['+', '-', '*', '/'], not {operation!r}.") if cls.display_mode == "power": # Order elements by powers of the primitive element @@ -686,7 +686,7 @@ def primitive_root_of_unity(cls, n: int) -> FieldArray: """ verify_isinstance(n, (int, np.ndarray)) if not 1 <= n < cls.order: - raise ValueError(f"Argument `n` must be in [1, {cls.order}), not {n}.") + raise ValueError(f"Argument 'n' must be in [1, {cls.order}), not {n}.") if not (cls.order - 1) % n == 0: raise ValueError(f"There are no primitive {n}-th roots of unity in {cls.name}.") @@ -750,7 +750,7 @@ def primitive_roots_of_unity(cls, n: int) -> FieldArray: np.power.outer(root, powers) """ if not isinstance(n, (int, np.ndarray)): - raise TypeError(f"Argument `n` must be an int, not {type(n)!r}.") + raise TypeError(f"Argument 'n' must be an int, not {type(n)!r}.") if not (cls.order - 1) % n == 0: raise ValueError(f"There are no primitive {n}-th roots of unity in {cls.name}.") diff --git a/src/galois/_fields/_factory.py b/src/galois/_fields/_factory.py index 926ab9067..2b4234749 100644 --- a/src/galois/_fields/_factory.py +++ b/src/galois/_fields/_factory.py @@ -203,17 +203,17 @@ def GF( p, e = factors(order) if not len(p) == len(e) == 1: s = " + ".join([f"{pi}**{ei}" for pi, ei in zip(p, e)]) - raise ValueError(f"Argument `order` must be a prime power, not {order} = {s}.") + raise ValueError(f"Argument 'order' must be a prime power, not {order} = {s}.") if not compile in [None, "auto", "jit-lookup", "jit-calculate", "python-calculate"]: - raise ValueError(f"Argument `compile` must be in ['auto', 'jit-lookup', 'jit-calculate', 'python-calculate'], not {compile!r}.") + raise ValueError(f"Argument 'compile' must be in ['auto', 'jit-lookup', 'jit-calculate', 'python-calculate'], not {compile!r}.") if not display in [None, "int", "poly", "power"]: - raise ValueError(f"Argument `display` must be in ['int', 'poly', 'power'], not {display!r}.") + raise ValueError(f"Argument 'display' must be in ['int', 'poly', 'power'], not {display!r}.") p, m = p[0], e[0] if m == 1: if not irreducible_poly is None: - raise ValueError(f"Argument `irreducible_poly` can only be specified for extension fields, not the prime field GF({p}).") + raise ValueError(f"Argument 'irreducible_poly' can only be specified for extension fields, not the prime field GF({p}).") return _GF_prime(p, alpha=primitive_element, verify=verify, compile=compile, display=display) else: return _GF_extension(p, m, irreducible_poly_=irreducible_poly, alpha=primitive_element, verify=verify, compile=compile, display=display) @@ -252,7 +252,7 @@ def _GF_prime( # Check primitive element range if not 0 < alpha < p: - raise ValueError(f"Argument `primitive_element` must be non-zero in the field 0 < x < {p}, not {alpha}.") + raise ValueError(f"Argument 'primitive_element' must be non-zero in the field 0 < x < {p}, not {alpha}.") # If the requested field has already been constructed, return it name = f"FieldArray_{p}_{alpha}" @@ -266,7 +266,7 @@ def _GF_prime( return field if verify and not is_primitive_root(alpha, p): - raise ValueError(f"Argument `primitive_element` must be a primitive root modulo {p}, {alpha} is not.") + raise ValueError(f"Argument 'primitive_element' must be a primitive root modulo {p}, {alpha} is not.") if p == 2: field = GF2 @@ -337,13 +337,13 @@ def _GF_extension( # Check polynomial fields and degrees if not irreducible_poly_.field.order == p: - raise ValueError(f"Argument `irreducible_poly` must be over {prime_subfield.name}, not {irreducible_poly_.field.name}.") + raise ValueError(f"Argument 'irreducible_poly' must be over {prime_subfield.name}, not {irreducible_poly_.field.name}.") if not irreducible_poly_.degree == m: - raise ValueError(f"Argument `irreducible_poly` must have degree equal to {m}, not {irreducible_poly_.degree}.") + raise ValueError(f"Argument 'irreducible_poly' must have degree equal to {m}, not {irreducible_poly_.degree}.") if not alpha.field.order == p: - raise ValueError(f"Argument `primitive_element` must be a polynomial over {prime_subfield.name}, not {alpha.field.name}.") + raise ValueError(f"Argument 'primitive_element' must be a polynomial over {prime_subfield.name}, not {alpha.field.name}.") if not alpha.degree < m: - raise ValueError(f"Argument `primitive_element` must have degree strictly less than {m}, not {alpha.degree}.") + raise ValueError(f"Argument 'primitive_element' must have degree strictly less than {m}, not {alpha.degree}.") # If the requested field has already been constructed, return it name = f"FieldArray_{p}_{m}_{int(alpha)}_{int(irreducible_poly_)}" @@ -357,9 +357,9 @@ def _GF_extension( return field if verify_poly and not irreducible_poly_.is_irreducible(): - raise ValueError(f"Argument `irreducible_poly` must be irreducible, {irreducible_poly_} is not.") + raise ValueError(f"Argument 'irreducible_poly' must be irreducible, {irreducible_poly_} is not.") if verify_element and not is_primitive_element(alpha, irreducible_poly_): - raise ValueError(f"Argument `primitive_element` must be a multiplicative generator of {name}, {alpha} is not.") + raise ValueError(f"Argument 'primitive_element' must be a multiplicative generator of {name}, {alpha} is not.") ufunc_mixin = UFuncMixin_2_m if p == 2 else UFuncMixin_p_m diff --git a/src/galois/_fields/_primitive_element.py b/src/galois/_fields/_primitive_element.py index f97f8c604..a0250dfaa 100644 --- a/src/galois/_fields/_primitive_element.py +++ b/src/galois/_fields/_primitive_element.py @@ -65,11 +65,11 @@ def is_primitive_element(element: PolyLike, irreducible_poly: Poly) -> bool: element = Poly._PolyLike(element, field=field) if not element.field == irreducible_poly.field: - raise ValueError(f"Arguments `element` and `irreducible_poly` must be over the same field, not {element.field.name} and {irreducible_poly.field.name}.") + raise ValueError(f"Arguments 'element' and 'irreducible_poly' must be over the same field, not {element.field.name} and {irreducible_poly.field.name}.") if not element.degree < irreducible_poly.degree: - raise ValueError(f"Argument `element` must have degree less than `irreducible_poly`, not {element.degree} and {irreducible_poly.degree}.") + raise ValueError(f"Argument 'element' must have degree less than 'irreducible_poly', not {element.degree} and {irreducible_poly.degree}.") if not irreducible_poly.is_irreducible(): - raise ValueError(f"Argument `irreducible_poly` must be irreducible, {irreducible_poly} is reducible over {irreducible_poly.field.name}.") + raise ValueError(f"Argument 'irreducible_poly' must be irreducible, {irreducible_poly} is reducible over {irreducible_poly.field.name}.") return _is_primitive_element(element, irreducible_poly) @@ -165,11 +165,11 @@ def primitive_element(irreducible_poly: Poly, method: Literal["min", "max", "ran """ verify_isinstance(irreducible_poly, Poly) if not irreducible_poly.degree > 1: - raise ValueError(f"Argument `irreducible_poly` must have degree greater than 1, not {irreducible_poly.degree}.") + raise ValueError(f"Argument 'irreducible_poly' must have degree greater than 1, not {irreducible_poly.degree}.") if not irreducible_poly.is_irreducible(): - raise ValueError(f"Argument `irreducible_poly` must be irreducible, {irreducible_poly} is reducible over {irreducible_poly.field.name}.") + raise ValueError(f"Argument 'irreducible_poly' must be irreducible, {irreducible_poly} is reducible over {irreducible_poly.field.name}.") if not method in ["min", "max", "random"]: - raise ValueError(f"Argument `method` must be in ['min', 'max', 'random'], not {method!r}.") + raise ValueError(f"Argument 'method' must be in ['min', 'max', 'random'], not {method!r}.") field = irreducible_poly.field q = irreducible_poly.field.order diff --git a/src/galois/_lfsr.py b/src/galois/_lfsr.py index f0cf4d0ef..26dcecc14 100644 --- a/src/galois/_lfsr.py +++ b/src/galois/_lfsr.py @@ -35,7 +35,7 @@ def __init__( ): verify_isinstance(feedback_poly, Poly) if not feedback_poly.coeffs[-1] == 1: - raise ValueError(f"Argument `feedback_poly` must have a 0-th degree term of 1, not {feedback_poly}.") + raise ValueError(f"Argument 'feedback_poly' must have a 0-th degree term of 1, not {feedback_poly}.") self._field = feedback_poly.field self._feedback_poly = feedback_poly @@ -83,7 +83,7 @@ def _verify_and_convert_state(self, state: ArrayLike): # if not state.size == self.order: if not state.size == self.order: - raise ValueError(f"Argument `state` must have size equal to the degree of the characteristic polynomial, not {state.size} and {self.characteristic_poly.degree}.") + raise ValueError(f"Argument 'state' must have size equal to the degree of the characteristic polynomial, not {state.size} and {self.characteristic_poly.degree}.") return state @@ -1572,9 +1572,9 @@ def berlekamp_massey(sequence, output="minimal"): verify_isinstance(sequence, FieldArray) verify_isinstance(output, str) if not sequence.ndim == 1: - raise ValueError(f"Argument `sequence` must be 1-D, not {sequence.ndim}-D.") + raise ValueError(f"Argument 'sequence' must be 1-D, not {sequence.ndim}-D.") if not output in ["minimal", "fibonacci", "galois"]: - raise ValueError(f"Argument `output` must be in ['minimal', 'fibonacci', 'galois'], not {output!r}.") + raise ValueError(f"Argument 'output' must be in ['minimal', 'fibonacci', 'galois'], not {output!r}.") field = type(sequence) coeffs = berlekamp_massey_jit(field)(sequence) diff --git a/src/galois/_math.py b/src/galois/_math.py index d9413567e..2c14d7b4e 100644 --- a/src/galois/_math.py +++ b/src/galois/_math.py @@ -110,7 +110,7 @@ def isqrt(n: int) -> int: verify_isinstance(n, int) if not n >= 0: - raise ValueError(f"Argument `n` must be non-negative, not {n}.") + raise ValueError(f"Argument 'n' must be non-negative, not {n}.") if n < 2: return n @@ -158,9 +158,9 @@ def iroot(n: int, k: int) -> int: verify_isinstance(n, int) verify_isinstance(k, int) if not n >= 0: - raise ValueError(f"Argument `n` must be non-negative, not {n}.") + raise ValueError(f"Argument 'n' must be non-negative, not {n}.") if not k >= 1: - raise ValueError(f"Argument `k` must be at least 1, not {k}.") + raise ValueError(f"Argument 'k' must be at least 1, not {k}.") if n == 0: return 0 @@ -213,9 +213,9 @@ def ilog(n: int, b: int) -> int: verify_isinstance(n, int) verify_isinstance(b, int) if not n > 0: - raise ValueError(f"Argument `n` must be positive, not {n}.") + raise ValueError(f"Argument 'n' must be positive, not {n}.") if not b >= 2: - raise ValueError(f"Argument `b` must be at least 2, not {b}.") + raise ValueError(f"Argument 'b' must be at least 2, not {b}.") # https://stackoverflow.com/a/39191163/11694321 low, b_low, high, b_high = 0, 1, 1, b diff --git a/src/galois/_modular.py b/src/galois/_modular.py index 83604911f..7eb4571a0 100644 --- a/src/galois/_modular.py +++ b/src/galois/_modular.py @@ -57,7 +57,7 @@ def totatives(n: int) -> list[int]: """ verify_isinstance(n, int) if not n > 0: - raise ValueError(f"Argument `n` must be a positive integer, not {n}.") + raise ValueError(f"Argument 'n' must be a positive integer, not {n}.") if n == 1: return [0] @@ -131,7 +131,7 @@ def euler_phi(n: int) -> int: def _euler_phi(n: int) -> int: verify_isinstance(n, int) if not n > 0: - raise ValueError(f"Argument `n` must be a positive integer, not {n}.") + raise ValueError(f"Argument 'n' must be a positive integer, not {n}.") if n == 1: return 1 @@ -218,7 +218,7 @@ def carmichael_lambda(n: int) -> int: """ verify_isinstance(n, int) if not n > 0: - raise ValueError(f"Argument `n` must be a positive integer, not {n}.") + raise ValueError(f"Argument 'n' must be a positive integer, not {n}.") if n == 1: return 1 @@ -380,7 +380,7 @@ def is_cyclic(n: int) -> bool: """ verify_isinstance(n, int) if not n > 0: - raise ValueError(f"Argument `n` must be a positive integer, not {n}.") + raise ValueError(f"Argument 'n' must be a positive integer, not {n}.") if n == 1: return True @@ -559,9 +559,9 @@ def primitive_root(n: int, start: int = 1, stop: int | None = None, method: Lite stop = n if stop is None else stop if not 1 <= start < stop <= n: - raise ValueError(f"Arguments must satisfy `1 <= start < stop <= n`, not `1 <= {start} < {stop} <= {n}`.") + raise ValueError(f"Arguments must satisfy 1 <= start < stop <= n, not 1 <= {start} < {stop} <= {n}.") if not method in ["min", "max", "random"]: - raise ValueError(f"Argument `method` must be in ['min', 'max', 'random'], not {method!r}.") + raise ValueError(f"Argument 'method' must be in ['min', 'max', 'random'], not {method!r}.") try: if method == "min": @@ -775,9 +775,9 @@ def is_primitive_root(g: int, n: int) -> bool: verify_isinstance(g, int) verify_isinstance(n, int) if not n > 0: - raise ValueError(f"Argument `n` must be a positive integer, not {n}.") + raise ValueError(f"Argument 'n' must be a positive integer, not {n}.") if not 0 < g < n: - raise ValueError(f"Argument `g` must be a positive integer less than `n`, not {g}.") + raise ValueError(f"Argument 'g' must be a positive integer less than 'n', not {g}.") return _is_primitive_root(g, n) diff --git a/src/galois/_ntt.py b/src/galois/_ntt.py index 8dadb4d11..1ae98db5d 100644 --- a/src/galois/_ntt.py +++ b/src/galois/_ntt.py @@ -12,11 +12,7 @@ @export -def ntt( - x: ArrayLike, - size: int | None = None, - modulus: int | None = None -) -> FieldArray: +def ntt(x: ArrayLike, size: int | None = None, modulus: int | None = None) -> FieldArray: r""" Computes the Number-Theoretic Transform (NTT) of :math:`x`. @@ -123,12 +119,7 @@ def ntt( @export -def intt( - X: ArrayLike, - size: int | None = None, - modulus: int | None = None, - scaled: bool = True -) -> FieldArray: +def intt(X: ArrayLike, size: int | None = None, modulus: int | None = None, scaled: bool = True) -> FieldArray: r""" Computes the Inverse Number-Theoretic Transform (INTT) of :math:`X`. @@ -264,13 +255,13 @@ def _ntt(x, size=None, modulus=None, forward=True, scaled=True): m = (modulus - 1) // size if not size >= len(x): - raise ValueError(f"Argument `size` must be at least the length of the input which is {len(x)}, not {size}.") + raise ValueError(f"Argument 'size' must be at least the length of the input which is {len(x)}, not {size}.") if not is_prime(modulus): - raise ValueError(f"Argument `modulus` must be prime, {modulus} is not.") + raise ValueError(f"Argument 'modulus' must be prime, {modulus} is not.") if not (modulus - 1) % size == 0: - raise ValueError("Argument `modulus` must satisfy `modulus = m*size + 1` where `size` is the size of the NTT transform.") + raise ValueError("Argument 'modulus' must equal m * size + 1, where 'size' is the size of the NTT transform.") if not modulus > np.max(x): - raise ValueError(f"Argument `modulus` must be at least the max value of the input which is {np.max(x)}, not {modulus}.") + raise ValueError(f"Argument 'modulus' must be at least the max value of the input which is {np.max(x)}, not {modulus}.") field = Field(modulus) # The prime field GF(p) diff --git a/src/galois/_options.py b/src/galois/_options.py index 659b5fef2..e74bb7561 100644 --- a/src/galois/_options.py +++ b/src/galois/_options.py @@ -52,7 +52,7 @@ def set_printoptions( :group: config """ if not coeffs in ["desc", "asc"]: - raise ValueError(f"Argument `coeffs` must be in ['desc', 'asc'], not {coeffs}.") + raise ValueError(f"Argument 'coeffs' must be in ['desc', 'asc'], not {coeffs}.") PRINTOPTIONS["coeffs"] = coeffs diff --git a/src/galois/_polymorphic.py b/src/galois/_polymorphic.py index cc0a7ae98..4b6bc7746 100644 --- a/src/galois/_polymorphic.py +++ b/src/galois/_polymorphic.py @@ -490,11 +490,11 @@ def crt(remainders, moduli): print(ai, ai == a[i]) """ if not (isinstance(remainders, (tuple, list)) and (all(isinstance(x, (int, np.integer)) for x in remainders) or all(isinstance(x, Poly) for x in remainders))): - raise TypeError(f"Argument `remainders` must be a tuple or list of int or galois.Poly, not {remainders}.") + raise TypeError(f"Argument 'remainders' must be a tuple or list of int or Poly, not {remainders}.") if not (isinstance(moduli, (tuple, list)) and (all(isinstance(x, (int, np.integer)) for x in moduli) or all(isinstance(x, Poly) for x in moduli))): - raise TypeError(f"Argument `moduli` must be a tuple or list of int or galois.Poly, not {moduli}.") + raise TypeError(f"Argument 'moduli' must be a tuple or list of int or Poly, not {moduli}.") if not len(remainders) == len(moduli) >= 2: - raise ValueError(f"Arguments `remainders` and `moduli` must be the same length of at least 2, not {len(remainders)} and {len(moduli)}.") + raise ValueError(f"Arguments 'remainders' and 'moduli' must be the same length of at least 2, not {len(remainders)} and {len(moduli)}.") # Ensure polynomial arguments have each remainder have degree less than its modulus if isinstance(remainders[0], Poly): @@ -648,7 +648,7 @@ def factors(value): elif isinstance(value, Poly): return value.factors() else: - raise TypeError(f"Argument `value` must be either int or galois.Poly, not {type(value)}.") + raise TypeError(f"Argument 'value' must be either int or Poly, not {type(value)}.") @overload @@ -739,4 +739,4 @@ def is_square_free(value): elif isinstance(value, Poly): return value.is_square_free() else: - raise TypeError(f"Argument `value` must be either int or galois.Poly, not {type(value)}.") + raise TypeError(f"Argument 'value' must be either int or Poly, not {type(value)}.") diff --git a/src/galois/_polys/_functions.py b/src/galois/_polys/_functions.py index c288a7808..7245c3b65 100644 --- a/src/galois/_polys/_functions.py +++ b/src/galois/_polys/_functions.py @@ -164,15 +164,15 @@ def lagrange_poly(x: Array, y: Array) -> Poly: verify_isinstance(x, Array) verify_isinstance(y, Array) if not type(x) == type(y): # pylint: disable=unidiomatic-typecheck - raise TypeError(f"Arguments `x` and `y` must be over the same Galois field, not {type(x)} and {type(y)}.") + raise TypeError(f"Arguments 'x' and 'y' must be over the same Galois field, not {type(x)} and {type(y)}.") if not x.ndim == 1: - raise ValueError(f"Argument `x` must be 1-D, not have shape {x.shape}.") + raise ValueError(f"Argument 'x' must be 1-D, not have shape {x.shape}.") if not y.ndim == 1: - raise ValueError(f"Argument `y` must be 1-D, not have shape {y.shape}.") + raise ValueError(f"Argument 'y' must be 1-D, not have shape {y.shape}.") if not x.size == y.size: - raise ValueError(f"Arguments `x` and `y` must be the same size, not {x.size} and {y.size}.") + raise ValueError(f"Arguments 'x' and 'y' must be the same size, not {x.size} and {y.size}.") if not x.size == np.unique(x).size: - raise ValueError(f"Argument `x` must have unique entries, not {x}.") + raise ValueError(f"Argument 'x' must have unique entries, not {x}.") field = type(x) L = Poly.Zero(field) # The Lagrange polynomial L(x) diff --git a/src/galois/_polys/_irreducible.py b/src/galois/_polys/_irreducible.py index 68bdd5e08..f57070cd4 100644 --- a/src/galois/_polys/_irreducible.py +++ b/src/galois/_polys/_irreducible.py @@ -75,11 +75,11 @@ def irreducible_poly(order: int, degree: int, method: Literal["min", "max", "ran verify_isinstance(order, int) verify_isinstance(degree, int) if not is_prime_power(order): - raise ValueError(f"Argument `order` must be a prime power, not {order}.") + raise ValueError(f"Argument 'order' must be a prime power, not {order}.") if not degree >= 1: - raise ValueError(f"Argument `degree` must be at least 1, not {degree}. There are no irreducible polynomials with degree 0.") + raise ValueError(f"Argument 'degree' must be at least 1, not {degree}. There are no irreducible polynomials with degree 0.") if not method in ["min", "max", "random"]: - raise ValueError(f"Argument `method` must be in ['min', 'max', 'random'], not {method!r}.") + raise ValueError(f"Argument 'method' must be in ['min', 'max', 'random'], not {method!r}.") if method == "min": return next(irreducible_polys(order, degree)) @@ -153,9 +153,9 @@ def irreducible_polys(order: int, degree: int, reverse: bool = False) -> Iterato verify_isinstance(degree, int) verify_isinstance(reverse, bool) if not is_prime_power(order): - raise ValueError(f"Argument `order` must be a prime power, not {order}.") + raise ValueError(f"Argument 'order' must be a prime power, not {order}.") if not degree >= 0: - raise ValueError(f"Argument `degree` must be at least 0, not {degree}.") + raise ValueError(f"Argument 'degree' must be at least 0, not {degree}.") field = _factory.FIELD_FACTORY(order) diff --git a/src/galois/_polys/_poly.py b/src/galois/_polys/_poly.py index 33e84fda1..4621c3f49 100644 --- a/src/galois/_polys/_poly.py +++ b/src/galois/_polys/_poly.py @@ -98,9 +98,9 @@ def __init__(self, coeffs: ArrayLike, field: Type[Array] | None = None, order: L verify_issubclass(field, Array, optional=True) verify_isinstance(order, str) if isinstance(coeffs, (Array, np.ndarray)) and not coeffs.ndim <= 1: - raise ValueError(f"Argument `coeffs` can have dimension at most 1, not {coeffs.ndim}.") + raise ValueError(f"Argument 'coeffs' can have dimension at most 1, not {coeffs.ndim}.") if not order in ["desc", "asc"]: - raise ValueError(f"Argument `order` must be either 'desc' or 'asc', not {order!r}.") + raise ValueError(f"Argument 'order' must be either 'desc' or 'asc', not {order!r}.") self._coeffs, self._field = _convert_coeffs(coeffs, field) @@ -290,9 +290,9 @@ def Random(cls, degree: int, seed: int | np.integer | np.random.Generator | None field = _factory.DEFAULT_ARRAY if field is None else field if seed is not None: if isinstance(seed, int) and not seed >= 0: - raise ValueError(f"Argument `seed` must be non-negative, not {seed}.") + raise ValueError(f"Argument 'seed' must be non-negative, not {seed}.") if not degree >= 0: - raise ValueError(f"Argument `degree` must be non-negative, not {degree}.") + raise ValueError(f"Argument 'degree' must be non-negative, not {degree}.") rng = np.random.default_rng(seed) # Make the seed a PRNG object so it can "step" its state if the below "if" statement is invoked coeffs = field.Random(degree + 1, seed=rng) @@ -421,7 +421,7 @@ def Int(cls, integer: int, field: Type[Array] | None = None) -> Poly: field = _factory.DEFAULT_ARRAY if field is None else field if not integer >= 0: - raise ValueError(f"Argument `integer` must be non-negative, not {integer}.") + raise ValueError(f"Argument 'integer' must be non-negative, not {integer}.") obj = object.__new__(cls) obj._integer = integer @@ -481,22 +481,22 @@ def Degrees( verify_isinstance(degrees, (list, tuple, np.ndarray)) verify_isinstance(coeffs, (list, tuple, np.ndarray, Array), optional=True) if not (field is None or issubclass(field, Array)): - raise TypeError(f"Argument `field` must be a Array subclass, not {type(field)}.") + raise TypeError(f"Argument 'field' must be a Array subclass, not {type(field)}.") degrees = np.array(degrees, dtype=np.int64) coeffs = [1,]*len(degrees) if coeffs is None else coeffs coeffs, field = _convert_coeffs(coeffs, field) if not degrees.ndim <= 1: - raise ValueError(f"Argument `degrees` can have dimension at most 1, not {degrees.ndim}.") + raise ValueError(f"Argument 'degrees' can have dimension at most 1, not {degrees.ndim}.") if not degrees.size == np.unique(degrees).size: - raise ValueError(f"Argument `degrees` must have unique entries, not {degrees}.") + raise ValueError(f"Argument 'degrees' must have unique entries, not {degrees}.") if not np.all(degrees >= 0): - raise ValueError(f"Argument `degrees` must have non-negative values, not {degrees}.") + raise ValueError(f"Argument 'degrees' must have non-negative values, not {degrees}.") if not coeffs.ndim <= 1: - raise ValueError(f"Argument `coeffs` can have dimension at most 1, not {coeffs.ndim}.") + raise ValueError(f"Argument 'coeffs' can have dimension at most 1, not {coeffs.ndim}.") if not degrees.size == coeffs.size: - raise ValueError(f"Arguments `degrees` and `coeffs` must have the same length, not {degrees.size} and {coeffs.size}.") + raise ValueError(f"Arguments 'degrees' and 'coeffs' must have the same length, not {degrees.size} and {coeffs.size}.") # Only keep non-zero coefficients idxs = np.nonzero(coeffs) @@ -589,13 +589,13 @@ def Roots( verify_isinstance(roots, (tuple, list, np.ndarray, Array)) verify_isinstance(multiplicities, (tuple, list, np.ndarray)) if not (field is None or issubclass(field, Array)): - raise TypeError(f"Argument `field` must be a Array subclass, not {field}.") + raise TypeError(f"Argument 'field' must be a Array subclass, not {field}.") roots, field = _convert_coeffs(roots, field) roots = field(roots).flatten() if not len(roots) == len(multiplicities): - raise ValueError(f"Arguments `roots` and `multiplicities` must have the same length, not {len(roots)} and {len(multiplicities)}.") + raise ValueError(f"Arguments 'roots' and 'multiplicities' must have the same length, not {len(roots)} and {len(multiplicities)}.") poly = Poly.One(field=field) x = Poly.Identity(field=field) @@ -660,9 +660,9 @@ def coefficients( verify_isinstance(order, str) size = len(self) if size is None else size if not size >= len(self): - raise ValueError(f"Argument `size` must be at least `degree + 1` which is {len(self)}, not {size}.") + raise ValueError(f"Argument 'size' must be at least degree + 1 ({len(self)}), not {size}.") if not order in ["desc", "asc"]: - raise ValueError(f"Argument `order` must be either 'desc' or 'asc', not {order!r}.") + raise ValueError(f"Argument 'order' must be either 'desc' or 'asc', not {order!r}.") coeffs = self.field.Zeros(size) coeffs[-len(self):] = self.coeffs @@ -1046,7 +1046,7 @@ def equal_degree_factors(self, degree: int) -> list[Poly]: if not self.is_monic: raise ValueError(f"The polynomial must be monic, not {self}.") if not self.degree % degree == 0: - raise ValueError(f"Argument `degree` must be divide the degree of the polynomial, {degree} does not divide {self.degree}.") + raise ValueError(f"Argument 'degree' must be divide the degree of the polynomial, {degree} does not divide {self.degree}.") if not self.is_square_free(): raise ValueError(f"The polynomial must be square-free, not {self}.") @@ -1233,7 +1233,7 @@ def derivative(self, k: int = 1) -> Poly: """ verify_isinstance(k, int) if not k > 0: - raise ValueError(f"Argument `k` must be a positive integer, not {k}.") + raise ValueError(f"Argument 'k' must be a positive integer, not {k}.") if 0 in self.nonzero_degrees: # Cut off the 0th degree @@ -1637,7 +1637,7 @@ def __call__(self, at, field=None, elementwise=True): return _evaluate_poly(self, at) if not (field is None or issubclass(field, Array)): - raise TypeError(f"Argument `field` must be a Array subclass, not {type(field)}.") + raise TypeError(f"Argument 'field' must be a Array subclass, not {type(field)}.") field = self.field if field is None else field coeffs = field(self.coeffs) @@ -1647,7 +1647,7 @@ def __call__(self, at, field=None, elementwise=True): return _dense.evaluate_elementwise_jit(field)(coeffs, x) else: if not (x.ndim == 2 and x.shape[0] == x.shape[1]): - raise ValueError(f"Argument `x` must be a square matrix when evaluating the polynomial not element-wise, not have shape {x.shape}.") + raise ValueError(f"Argument 'x' must be a square matrix when evaluating the polynomial not element-wise, not have shape {x.shape}.") return _evaluate_matrix(coeffs, x) def __len__(self) -> int: diff --git a/src/galois/_polys/_primitive.py b/src/galois/_polys/_primitive.py index 3e06b7417..eedc5bf41 100644 --- a/src/galois/_polys/_primitive.py +++ b/src/galois/_polys/_primitive.py @@ -95,11 +95,11 @@ def primitive_poly(order: int, degree: int, method: Literal["min", "max", "rando verify_isinstance(degree, int) if not is_prime_power(order): - raise ValueError(f"Argument `order` must be a prime power, not {order}.") + raise ValueError(f"Argument 'order' must be a prime power, not {order}.") if not degree >= 1: - raise ValueError(f"Argument `degree` must be at least 1, not {degree}. There are no primitive polynomials with degree 0.") + raise ValueError(f"Argument 'degree' must be at least 1, not {degree}. There are no primitive polynomials with degree 0.") if not method in ["min", "max", "random"]: - raise ValueError(f"Argument `method` must be in ['min', 'max', 'random'], not {method!r}.") + raise ValueError(f"Argument 'method' must be in ['min', 'max', 'random'], not {method!r}.") if method == "min": return next(primitive_polys(order, degree)) @@ -176,9 +176,9 @@ def primitive_polys(order: int, degree: int, reverse: bool = False) -> Iterator[ verify_isinstance(reverse, bool) if not is_prime_power(order): - raise ValueError(f"Argument `order` must be a prime power, not {order}.") + raise ValueError(f"Argument 'order' must be a prime power, not {order}.") if not degree >= 0: - raise ValueError(f"Argument `degree` must be at least 0, not {degree}.") + raise ValueError(f"Argument 'degree' must be at least 0, not {degree}.") field = _factory.FIELD_FACTORY(order) @@ -293,9 +293,9 @@ def conway_poly(characteristic: int, degree: int) -> Poly: verify_isinstance(degree, int) if not is_prime(characteristic): - raise ValueError(f"Argument `characteristic` must be prime, not {characteristic}.") + raise ValueError(f"Argument 'characteristic' must be prime, not {characteristic}.") if not degree >= 1: - raise ValueError(f"Argument `degree` must be at least 1, not {degree}. There are no primitive polynomials with degree 0.") + raise ValueError(f"Argument 'degree' must be at least 1, not {degree}. There are no primitive polynomials with degree 0.") coeffs = ConwayPolyDatabase().fetch(characteristic, degree) field = _factory.FIELD_FACTORY(characteristic) @@ -363,9 +363,9 @@ def matlab_primitive_poly(characteristic: int, degree: int) -> Poly: verify_isinstance(degree, int) if not is_prime(characteristic): - raise ValueError(f"Argument `characteristic` must be prime, not {characteristic}.") + raise ValueError(f"Argument 'characteristic' must be prime, not {characteristic}.") if not degree >= 1: - raise ValueError(f"Argument `degree` must be at least 1, not {degree}. There are no primitive polynomials with degree 0.") + raise ValueError(f"Argument 'degree' must be at least 1, not {degree}. There are no primitive polynomials with degree 0.") # Textbooks and Matlab use the lexicographically-minimal primitive polynomial for the default. But for some # reason, there are three exceptions. I can't determine why. diff --git a/src/galois/_prime.py b/src/galois/_prime.py index 0987fd2c0..021468e36 100644 --- a/src/galois/_prime.py +++ b/src/galois/_prime.py @@ -140,7 +140,7 @@ def kth_prime(k: int) -> int: """ verify_isinstance(k, int) if not 1 <= k <= MAX_K: - raise ValueError(f"Argument `k` is out of range of the prime lookup table. The lookup table only contains the first {MAX_K} primes (up to {MAX_N}).") + raise ValueError(f"Argument 'k' is out of range of the prime lookup table. The lookup table only contains the first {MAX_K} primes (up to {MAX_N}).") return PRIMES[k - 1] @@ -287,7 +287,7 @@ def random_prime(bits: int, seed: int | None = None) -> int: verify_isinstance(bits, int) verify_isinstance(seed, int, optional=True) if not bits > 0: - raise ValueError(f"Argument `bits` must be positive, not {bits}.") + raise ValueError(f"Argument 'bits' must be positive, not {bits}.") random.seed(seed) while True: @@ -344,7 +344,7 @@ def mersenne_exponents(n: int | None = None) -> list[int]: verify_isinstance(n, int) if not n > 0: - raise ValueError(f"Argument `n` must be positive, not {n}.") + raise ValueError(f"Argument 'n' must be positive, not {n}.") return MERSENNE_EXPONENTS[0:bisect.bisect_right(MERSENNE_EXPONENTS, n)] @@ -477,11 +477,11 @@ def fermat_primality_test(n: int, a: int | None = None, rounds: int = 1) -> bool a = random.randint(2, n - 2) if a is None else a if not (n > 2 and n % 2 == 1): - raise ValueError(f"Argument `n` must be odd and greater than 2, not {n}.") + raise ValueError(f"Argument 'n' must be odd and greater than 2, not {n}.") if not 2 <= a <= n - 2: - raise ValueError(f"Argument `a` must satisfy 2 <= a <= {n - 2}, not {a}.") + raise ValueError(f"Argument 'a' must satisfy 2 <= a <= {n - 2}, not {a}.") if not rounds >= 1: - raise ValueError(f"Argument `rounds` must be at least 1, not {rounds}.") + raise ValueError(f"Argument 'rounds' must be at least 1, not {rounds}.") for _ in range(rounds): if pow(a, n - 1, n) != 1: @@ -572,11 +572,11 @@ def miller_rabin_primality_test(n: int, a: int = 2, rounds: int = 1) -> bool: return True if not (n > 2 and n % 2 == 1): - raise ValueError(f"Argument `n` must be odd and greater than 2, not {n}.") + raise ValueError(f"Argument 'n' must be odd and greater than 2, not {n}.") if not 2 <= a <= n - 2: - raise ValueError(f"Argument `a` must satisfy 2 <= a <= {n - 2}, not {a}.") + raise ValueError(f"Argument 'a' must satisfy 2 <= a <= {n - 2}, not {a}.") if not rounds >= 1: - raise ValueError(f"Argument `rounds` must be at least 1, not {rounds}.") + raise ValueError(f"Argument 'rounds' must be at least 1, not {rounds}.") # Write (n - 1) = 2^s * r, for odd r r, s = n - 1, 0 @@ -663,7 +663,7 @@ def legendre_symbol(a: int, p: int) -> int: verify_isinstance(a, int) verify_isinstance(p, int) if not (is_prime(p) and p > 2): - raise ValueError(f"Argument `p` must be an odd prime greater than 2, not {p}.") + raise ValueError(f"Argument 'p' must be an odd prime greater than 2, not {p}.") return jacobi_symbol(a, p) @@ -716,7 +716,7 @@ def jacobi_symbol(a: int, n: int) -> int: verify_isinstance(a, int) verify_isinstance(n, int) if not (n > 2 and n % 2 == 1): - raise ValueError(f"Argument `n` must be an odd integer greater than 2, not {n}.") + raise ValueError(f"Argument 'n' must be an odd integer greater than 2, not {n}.") a = a % n if a == 0: @@ -822,7 +822,7 @@ def factors(n: int) -> tuple[list[int], list[int]]: """ verify_isinstance(n, int) if not n > 1: - raise ValueError(f"Argument `n` must be greater than 1, not {n}.") + raise ValueError(f"Argument 'n' must be greater than 1, not {n}.") # Step 1 if is_prime(n): @@ -1024,9 +1024,9 @@ def trial_division(n: int, B: int | None = None) -> tuple[list[int], list[int], B = isqrt(n) if B is None else B if not n > 1: - raise ValueError(f"Argument `n` must be greater than 1, not {n}.") + raise ValueError(f"Argument 'n' must be greater than 1, not {n}.") if not B > 2: - raise ValueError(f"Argument `B` must be greater than 2, not {B}.") + raise ValueError(f"Argument 'B' must be greater than 2, not {B}.") B = min(isqrt(n), B) # There cannot be a prime factor greater than sqrt(n) p, e = [], [] @@ -1136,9 +1136,9 @@ def pollard_p1(n: int, B: int, B2: int | None = None) -> int: verify_isinstance(B2, int, optional=True) if not (n % 2 == 1 and n > 2): - raise ValueError(f"Argument `n` must be odd and greater than 2, not {n}.") + raise ValueError(f"Argument 'n' must be odd and greater than 2, not {n}.") if not B > 2: - raise ValueError(f"Argument `B` must be greater than 2, not {B}.") + raise ValueError(f"Argument 'B' must be greater than 2, not {B}.") a = 2 # A value that is coprime to n (since n is odd) check_stride = 10 @@ -1240,9 +1240,9 @@ def pollard_rho(n: int, c: int = 1) -> int: verify_isinstance(c, int, optional=True) if not n > 1: - raise ValueError(f"Argument `n` must be greater than 1, not {n}.") + raise ValueError(f"Argument 'n' must be greater than 1, not {n}.") if not c not in [0, -2]: - raise ValueError("Argument `c` cannot be -2 or 0.") + raise ValueError("Argument 'c' cannot be -2 or 0.") n = abs(n) f = lambda x: (x**2 + c) % n @@ -1679,7 +1679,7 @@ def is_smooth(n: int, B: int) -> bool: verify_isinstance(n, int) verify_isinstance(B, int) if not B >= 2: - raise ValueError(f"Argument `B` must be at least 2, not {B}.") + raise ValueError(f"Argument 'B' must be at least 2, not {B}.") # Since -1 can factored out of the prime factorization is_square_free(-n) == is_square_free(n) n = abs(n) @@ -1743,7 +1743,7 @@ def is_powersmooth(n: int, B: int) -> bool: verify_isinstance(n, int) verify_isinstance(B, int) if not B >= 2: - raise ValueError(f"Argument `B` must be at least 2, not {B}.") + raise ValueError(f"Argument 'B' must be at least 2, not {B}.") # Since -1 can factored out of the prime factorization is_square_free(-n) == is_square_free(n) n = abs(n)