{"id":9001,"library":"galois","title":"Galois Fields for NumPy","description":"The `galois` library is a performant Python package that extends NumPy arrays to operate over finite fields (Galois fields) for various mathematical and cryptographic applications. It leverages Numba and LLVM for just-in-time compilation to optimize finite field arithmetic, often outperforming native NumPy operations for modular arithmetic. It supports all Galois fields GF(p^m), offering functionalities for linear algebra, polynomials, forward error correction codes (BCH, Reed-Solomon), and number theoretic functions. Currently at version 0.4.10, the library maintains an active release cadence, with updates typically arriving monthly or bi-monthly.","status":"active","version":"0.4.10","language":"en","source_language":"en","source_url":"https://github.com/mhostetter/galois","tags":["mathematics","finite fields","galois fields","numpy","cryptography","error correction","coding theory","algebra"],"install":[{"cmd":"pip install galois","lang":"bash","label":"Install latest stable release"}],"dependencies":[{"reason":"`galois` is built as an extension to NumPy arrays and is completely dependent on it for array operations.","package":"numpy","optional":false},{"reason":"`galois` heavily relies on Numba for just-in-time compilation to optimize the performance of finite field arithmetic.","package":"numba","optional":false},{"reason":"Used for type hinting, especially for compatibility across different Python versions.","package":"typing_extensions","optional":false}],"imports":[{"symbol":"galois","correct":"import galois"},{"note":"`galois.Field()` was deprecated in v0.4.10 and is slated for removal in v0.5.0. Use `galois.GF()` instead.","wrong":"GF = galois.Field(p**m)","symbol":"GF","correct":"GF = galois.GF(p**m)"},{"symbol":"Poly","correct":"P = galois.Poly([1, 0, 1], field=GF)"}],"quickstart":{"code":"import galois\nimport numpy as np\n\n# Define a Galois field, e.g., GF(3^5)\nGF = galois.GF(3**5)\nprint(f\"Galois Field properties:\\n{GF.properties}\")\n\n# Create FieldArray instances (which are subclasses of np.ndarray)\nx = GF([236, 87, 38, 112])\ny = GF(np.array([109, 201, 2, 45]))\n\nprint(f\"\\nx (type: {type(x)}): {x}\")\nprint(f\"y (type: {type(y)}): {y}\")\n\n# Perform arithmetic operations in the finite field\nresult_add = x + y\nresult_mul = x * y\n\nprint(f\"\\nx + y: {result_add}\")\nprint(f\"x * y: {result_mul}\")","lang":"python","description":"This quickstart demonstrates how to define a Galois field, create `FieldArray` instances which inherit from NumPy arrays, and perform basic arithmetic operations within that finite field. The `galois.GF()` factory function is used to create the field class."},"warnings":[{"fix":"Migrate all calls from `galois.Field()` to `galois.GF()`. They are functionally equivalent.","message":"The `galois.Field()` class factory function was deprecated in `galois` v0.4.10 and is scheduled for removal in v0.5.0.","severity":"breaking","affected_versions":">=0.4.10"},{"fix":"Always pass these specific arguments by keyword, not by position. For example, use `galois.GF(p**m, irreducible_poly=poly)` instead of `galois.GF(p**m, poly)`.","message":"As of `galois` v0.3.0, several keyword arguments for `galois.GF()` and `galois.Field()` (e.g., `irreducible_poly`, `primitive_element`, `verify`, `compile`, `repr`) can no longer be passed as positional arguments.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Do not use `galois` for production security-sensitive applications where constant-time arithmetic is a requirement. It is intended for research, development, cryptanalysis, and education.","message":"The algorithms implemented in `galois` are designed for performance, not constant-time execution. This means the library could be vulnerable to side-channel timing attacks.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If encountering `ImportError` or other runtime issues related to NumPy/Numba, check the official `galois` documentation for its recommended `numpy` and `numba` versions. Consider installing `numpy` and `numba` first, or using a virtual environment to isolate dependencies.","message":"`galois` depends heavily on Numba, which has historically had tight and sometimes incompatible dependencies with specific NumPy versions. This can lead to issues during installation or runtime if the installed NumPy and Numba versions are not compatible.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Replace `galois.Field(...)` with `galois.GF(...)`.","cause":"Attempting to use the `galois.Field()` class factory after it has been removed in a future version (v0.5.0).","error":"AttributeError: module 'galois' has no attribute 'Field'"},{"fix":"Ensure all such arguments are passed by keyword, e.g., `galois.GF(2**8, irreducible_poly=poly)`.","cause":"Passing keyword-only arguments like `irreducible_poly` or `primitive_element` positionally to `galois.GF()` (or `galois.Field()`) since v0.3.0.","error":"TypeError: galois.GF() takes no positional arguments for 'irreducible_poly'"},{"fix":"Ensure both `FieldArray` instances are created from the *exact same* `GF` class. If necessary, explicitly cast one array to the field of the other using `GF_target(array_source)` if the conversion is meaningful and defined.","cause":"Performing arithmetic between two `FieldArray` instances that represent elements from different Galois fields. Even if they have the same order (p^m), they must be defined with the exact same irreducible polynomial to be compatible.","error":"TypeError: arithmetic operation between FieldArray instances with different irreducible polynomials of order GF(p^m)"},{"fix":"If on Python 3.10.1, try upgrading to a later Python 3.10.x release, Python 3.11+, or downgrading to Python 3.9. Ensure Numba and NumPy are also updated to their latest compatible versions.","cause":"This issue was specifically reported with Python 3.10.1, likely due to a specific incompatibility between Numba's compiled components and that Python patch version.","error":"ImportError: DLL load failed while importing unicodedata: The specified module could not be found."}]}