A computational laboratory for finite field vector spaces, Hamming balls, and sumset structural analysis.
Project description
Finite-Field Spaces (ffspaces)
ffspaces is a lightweight Python toolkit for working with vectors over finite fields $\mathbb{F}_p^n$, with a focus on sumset analysis, linear-subspace structure, and Hamming-ball geometry.
The package is designed for small-to-medium computational experiments in additive combinatorics, coding theory, and related discrete geometry settings. It provides both direct implementations and faster specialized routines for common operations over finite fields.
Current functionality
- Finite-field vector spaces: generate the full vector space $\mathbb{F}_p^n$ or construct random invertible basis changes.
- Finite-field rank: compute matrix rank over $\mathbb{F}_p$ using modular Gaussian elimination.
- Sumsets: compute $S+S$ for a set of vectors over $\mathbb{F}_p^n$, including a direct reference method and a faster FWHT-based implementation.
- Subspace detection: find the largest linear subspace contained in a sumset, with both greedy and exhaustive search modes.
- Hamming-ball geometry: generate standard Hamming balls, compute Hamming weights, and build balls under arbitrary linear transforms.
- Cover constructions: build unions of Hamming balls and compute complements relative to a universe.
Features
- NumPy-based operations: vectorized generation and manipulation of finite-field vectors.
- Field-aware linear algebra: rank and invertibility checks performed over $\mathbb{F}_p$, not over the reals.
- Flexible geometry tools: support for binary and higher-characteristic experiments.
- Reusable experiment helpers: scripts and utilities in the
experiments/directory for one-off analysis.
Installation
Install from PyPI:
pip install ffspaces
Or clone the repository and install in editable mode:
git clone https://github.com/nathanhoehndorf/finite-field-spaces
cd finite-field-spaces
pip install -e .
The package requires Python 3.10+ and NumPy.
Package API
After installing with pip install ffspaces, import the public API from the package root:
from ffspaces import (
generate_space,
generate_random_basis,
is_invertible,
vectors_to_ints,
ints_to_vectors,
compute_sumset_fwht,
_compute_sumset_original,
compute_sumset,
compare_sumset_methods,
find_maximum_subspace_dimension,
generate_covering,
complement,
compute_hamming_weight,
generate_hamming_ball,
generate_standard_ball,
)
Core utilities
generate_space(n, p=2): returns all vectors in $\mathbb{F}_p^n$ as a NumPy array of shape(p**n, n).generate_random_basis(n, p=2, rng=None): returns a random invertiblen x nmatrix over $\mathbb{F}_p$.is_invertible(matrix, p=2): checks whether a square matrix is invertible over $\mathbb{F}_p$.
Vector encoding
vectors_to_ints(vectors, p=2): maps each row of a matrix in $\mathbb{Z}_p^n$ to a unique integer.ints_to_vectors(ints, n, p=2): converts integer codes back into $\mathbb{Z}_p^n$ vectors.
Sumset operations
compute_sumset_fwht(set_elements, p=2): computes the sumset $S+S$ using a Fourier-based transform over the finite field._compute_sumset_original(set_elements, p=2): computes $S+S$ by direct pairwise sums and unique filtering.compute_sumset(set_elements, p=2): alias for the fast FWHT-based sumset computation.compare_sumset_methods(n=6, subset_size=10, seed=None): generates a random binary subset and compares FWHT and direct sumset methods.
Subspace analysis
find_maximum_subspace_dimension(sumset, p=2, exhaustive=False, max_combinations=10000): returns the dimension of the largest linear subspace contained in a sumset.
Hamming geometry and covering
generate_standard_ball(n, r): returns all binary vectors in $\mathbb{F}_2^n$ with Hamming weight at mostr.compute_hamming_weight(vectors): computes Hamming weights for each row of a matrix.generate_hamming_ball(universe, center, radius, linear_transform, p=2): builds a Hamming ball in $\mathbb{F}_p^n$ under a linear basis transform.generate_covering(centers, radii, bases=None, p=2, universe=None): returns the union of Hamming balls defined bycenters,radii, and optional basis transforms.complement(universe, covered): returns vectors inuniversethat are not present incovered.
Example usage
import numpy as np
from ffspaces import generate_space, compute_sumset, find_maximum_subspace_dimension
space = generate_space(3, p=2)
subset = space[[0, 1, 2, 4]]
sumset = compute_sumset(subset, p=2)
dimension = find_maximum_subspace_dimension(sumset, p=2)
print("sumset shape:", sumset.shape)
print("max subspace dimension:", dimension)
from ffspaces import generate_standard_ball, generate_covering, complement
ball = generate_standard_ball(4, 2)
universe = generate_space(4, p=2)
covered = generate_covering([np.zeros(4, dtype=int)], [2], p=2)
missing = complement(universe, covered)
print("covered size:", covered.shape[0])
print("missing size:", missing.shape[0])
Mathematical background
This package works in the vector space $\mathbb{F}_p^n$, where each coordinate is taken modulo a prime $p$. In particular, $\mathbb{F}_2^n$ is the set of binary vectors of length $n$, with addition done coordinatewise modulo $2$.
- What is $\mathbb{F}_p^n$? A finite-dimensional vector space over the finite field with $p$ elements. For $p=2$, this is the space of binary vectors.
- What is $S+S$? For a set $S \subseteq \mathbb{F}_p^n$, the sumset $S+S$ is the set of all pairwise sums $x+y$ with $x,y \in S$, taken modulo $p$.
- What is a Hamming ball? A Hamming ball is the set of vectors within a given distance from a center, where distance is the number of coordinates in which two vectors differ (known as Hamming weight, or the Hamming metric).
- What is the covering problem? A covering problem asks whether a collection of balls (or other subsets) can be chosen so that their union contains all points in a given universe, or perhaps all points of a particular structure.
- Why does this matter? These objects are central in additive combinatorics, coding theory, and discrete geometry, and they provide a natural setting for studying how small sets expand under addition or how geometric configurations cover a space.
Quick example
import numpy as np
from ffspaces import generate_space, compute_sumset, find_maximum_subspace_dimension
space = generate_space(3, p=2)
subset = space[[0, 1, 2, 4]]
sumset = compute_sumset(subset, p=2)
dimension = find_maximum_subspace_dimension(sumset, p=2)
print(dimension)
Experiments
One-off analysis and experiment scripts live in the experiments/ directory so they stay separate from the installable package code in src/.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ffspaces-0.2.2.tar.gz.
File metadata
- Download URL: ffspaces-0.2.2.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51fe0e38f38279f9f23fcebd3728e27ca7f0ceff332ddeedd3c19f1bbba949e3
|
|
| MD5 |
cddf066c4a6af238b0f897584e83f5ed
|
|
| BLAKE2b-256 |
96634f2eee86348a3fca2cb6dc59b20b0572471a1530fc137d7c5d08bd9196c3
|
Provenance
The following attestation bundles were made for ffspaces-0.2.2.tar.gz:
Publisher:
publish.yml on nathanhoehndorf/finite-field-spaces
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ffspaces-0.2.2.tar.gz -
Subject digest:
51fe0e38f38279f9f23fcebd3728e27ca7f0ceff332ddeedd3c19f1bbba949e3 - Sigstore transparency entry: 2065065351
- Sigstore integration time:
-
Permalink:
nathanhoehndorf/finite-field-spaces@71abfa06482b487e06966f310442a95050703d6b -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/nathanhoehndorf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@71abfa06482b487e06966f310442a95050703d6b -
Trigger Event:
release
-
Statement type:
File details
Details for the file ffspaces-0.2.2-py3-none-any.whl.
File metadata
- Download URL: ffspaces-0.2.2-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82dd1d33c088634d6929a849366d3065c46594d6d5831979a51e8c40469ff63b
|
|
| MD5 |
8e69069a98e16b8bfbd26773a4f8ca89
|
|
| BLAKE2b-256 |
eae69eb22628673697572007dc93dc9e61e330aaacdae13f66925d3ded351f25
|
Provenance
The following attestation bundles were made for ffspaces-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on nathanhoehndorf/finite-field-spaces
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ffspaces-0.2.2-py3-none-any.whl -
Subject digest:
82dd1d33c088634d6929a849366d3065c46594d6d5831979a51e8c40469ff63b - Sigstore transparency entry: 2065065394
- Sigstore integration time:
-
Permalink:
nathanhoehndorf/finite-field-spaces@71abfa06482b487e06966f310442a95050703d6b -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/nathanhoehndorf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@71abfa06482b487e06966f310442a95050703d6b -
Trigger Event:
release
-
Statement type: