mixle-discrete
Discrete and algebraic numerical methods: integer/binary least squares, finite fields, and the combinatorial-numerics pillar of the mixle ecosystem.
Where mixle-pde handles continuous inverse problems (PDEs, ODEs, gradient-based fitting), mixle-discrete handles the discrete and exact ones: recovering integer parameters from noisy linear measurements, and computing exactly over finite fields. It is standalone (numpy only) and composes with the rest of the ecosystem but does not depend on it.
Install
pip install -e . # from a checkout
pip install -e ".[test]" # with the test extras
Quickstart
import numpy as np
from mixle_discrete import integer_least_squares, GF
# Recover an integer vector from noisy linear measurements — an exact closest-vector solve.
rng = np.random.default_rng(0)
A = rng.standard_normal((8, 4)) # 8 noisy measurements of 4 integer unknowns
x_true = np.array([3, -1, 4, -2])
b = A @ x_true + 0.05 * rng.standard_normal(8)
integer_least_squares(A, b) # -> array([ 3, -1, 4, -2]); exact despite the noise
# Exact linear algebra over a finite field — no floating point, no round-off.
F = GF(7)
F.solve([[2, 1], [1, 3]], [1, 0]) # -> array([2, 4]); solves M x = y in GF(7)
What's here
Integer and binary least squares
min ||A x - b||^2 where x is constrained to the integers, to {0, 1}, or to a box. This is the
closest-vector problem, and it is an inverse problem with a discrete solution space (GNSS carrier-phase
ambiguity resolution, MIMO detection, lattice decoding). The stack is lattice reduction plus search:
lll_reduce— LLL lattice basis reduction (size reduction + the Lovasz condition).babai_nearest_plane— Babai's nearest-plane approximate CVP.integer_least_squares— the exact optimum over the integers by Schnorr-Euchner sphere decoding with LLL preprocessing.box_integer_least_squares/boolean_least_squares— the box- and{0,1}-constrained variants.enumerate_integer_least_squares— the solution set, not just the argmin: every integer point within a residual radius, themax_solutionsbest, box-constrained or free, sorted by residual.integer_least_squares_posterior— the inverse-problem view: exact posterior weights over the enumerated candidates under Gaussian noise (lo=0, hi=1gives the boolean posterior over all2^nassignments).
Finite fields
Exact computation over GF(p) and GF(2^m): field arithmetic, linear algebra, and polynomials.
GF(p)/GF(2, m)— field construction and elementwise arithmetic.- linear algebra over a field — RREF, rank,
solve, nullspace, inverse, determinant, plus the complete solution set of any linear system:solution_set(particular + nullspace basis) andenumerate_solutions(allq^nullityof them, materialized). - polynomials over a field — add, multiply, divmod, gcd.
- large binary fields —
GF(2, m, use_tables=False)drops the O(2^m) log tables and runs tableless (carryless multiply + Fermat inversion) so the crypto sizes work, e.g.GF(2, 128)on the GHASH polynomial.
Hashing, sketching, and membership
The hash families that streaming structures need, and structures built on them.
MultiplyShift,PolynomialHash,TabulationHash— 2-universal / k-independent / 3-independent hash families, plusghash/gcm_ghash, the GHASH polynomial MAC over GF(2^128) (the crypto hash on the field).CountMinSketch,CountSketch,HyperLogLog— sublinear-space stream summaries: one-sided and unbiased frequency estimation and distinct-count.BloomFilter,CountingBloomFilter,CuckooFilter— approximate membership (set inclusion without storing the set); no false negatives, a tunable false-positive rate, and deletion (counting / cuckoo).
Coding theory, lattice cryptography, and SAT
ReedSolomon,BCH— error-correcting codes over GF(2^m) (Berlekamp-Massey, Chien search, Forney), correcting up tot = (n-k)/2errors;list_decodereturns every codeword within a chosen Hamming radius, including pasttwhere unique decoding must fail.lwe_keygen/lwe_encrypt/lwe_decryptand thering_lwe_*variants — Regev LWE and Ring-LWE public-key encryption, with all secret and error sampling drawn from the constant-time discrete Gaussian below. These are side-channel-conscious reference implementations for study, not production cryptography: pure Python cannot guarantee hardware constant-time, so use a vetted library (liboqs and friends) for real keys.belief_propagation,survey_propagation— the statistical-physics message-passing solvers for SAT, withbp_decimation/sp_decimation; survey propagation works nearer the random-3-SAT threshold where BP fails.enumerate_sat— the exact counterpart for smalln: every satisfying assignment, so the row count is the model count and the column means are the exact marginals BP estimates.
The discrete Gaussian has two samplers: sample_discrete_gaussian_1d (rejection, fast, not constant-time,
for the statistical CVP/SVP routines) and ConstantTimeDiscreteGaussian / sample_discrete_gaussian_cdt (a
fixed-point CDT with a single full-table compare — no early exit, no secret-dependent branch or memory access —
for the crypto path). The constant-time one removes the algorithmic side channels only; see the caveat above.
Statistical solvers
The exact solvers above are the ground truth; these are the statistical route to the same problems, useful
when the instance is too large for exact search. Every discrete optimization min E(x) becomes inference in a
Gibbs distribution p(x) ∝ exp(-E(x)/T), and the optimum is the mode.
sample_discrete_gaussian_1d,klein_sample— the discrete Gaussian over a lattice and the Klein/GPV sampler (a randomized Babai walk over the LLL-reduced basis), the primitive underneath lattice cryptography.cvp_sample/svp_sample— statistical closest- and shortest-vector solving by sampling.simulated_annealing— a generic Metropolis/Gibbs engine, withanneal_cvp,anneal_qubo(Ising), andanneal_ilpcovering integer least squares, QUBO, and integer programming through one energy interface.
These grade against the exact solvers: cvp_sample and anneal_cvp match integer_least_squares on the vast
majority of instances, anneal_qubo matches brute force over 2^n, and the sampler's distribution passes a
chi-square goodness-of-fit against the discrete-Gaussian pmf.
Fast logsumexp: tropical convolution and Zech logarithms
logsumexp is the addition of the log-semiring, and its T→0 limit is the max-plus (tropical) semiring. Two
number-/group-theoretic structures make it fast in the cases where it can be:
tropical— max-plus convolution via the fast Legendre-Fenchel transform (the "tropical Fourier transform"), which diagonalizes sup-convolution into pointwise addition.fast_max_plus_convolutionisO(n)on concave data (vs theO(n²)max_plus_convolutionreference),top_k_max_plus_convolutionkeeps the k best decompositions per output index (the k-best-paths view) where the plain convolution keeps one winner, andlse_convolutionis the temperature-smoothed logsumexp version that converges to it asT→0(gap≤ T·log n).BinaryField.log_add/zech_log— Zech logarithms, the exact finite-field logsumexp:log(gⁱ + gʲ) = i + Z(j−i)turns addition in the log representation into a single table gather. Verified against direct field addition over all of GF(2⁸) and sampled at GF(2¹⁶). (A log-table technique, so small-to-moderate fields only; large binary fields use tableless carryless multiply instead.)
Verification
Everything is checked against an exact reference: brute force over a bounded search space for the least-squares
solvers, closed-form invariants for lattice reduction, A @ inv(A) == I for field linear algebra, sympy for
the algebraic parts, the exact solvers themselves (plus chi-square goodness-of-fit) for the statistical ones,
and the naive O(n²) convolution / direct field addition for the tropical and Zech routines.
Tests
pytest # the full suite (-n auto via pyproject)
pytest tests/integer_ls_test.py -q # one file
Maintainers & contributors
Maintained by Grant Boquet (@gmboquet · grant.boquet@gmail.com).
Contributions, issues, and discussion are welcome — open a PR or an issue.
License
MIT — see LICENSE.
Metadata
Release files for mixle-discrete 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mixle_discrete-0.7.0.tar.gz | 59.9 kB | With provenance | Details for mixle_discrete-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mixle_discrete-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for mixle_discrete-0.7.0-py3-none-any.whl |
Total release size: 121.7 kB
Release files / mixle_discrete-0.7.0.tar.gz
| Download URL | mixle_discrete-0.7.0.tar.gz |
|---|---|
| Size | 59.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d45012cee3765e1029ebdc0ce5f5ca022840422660d5909a55a4fc6d1cea8f9
|
|
BLAKE2b-256 checksum How to use checksums |
fde88ad5072964b42f9f6ee272255bbb50b7b4510db525893bf72c2e57d0e694
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.
Transparency logRelease files / mixle_discrete-0.7.0-py3-none-any.whl
| Download URL | mixle_discrete-0.7.0-py3-none-any.whl |
|---|---|
| Size | 61.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2cfd5b816d79c6780704ce1176ff2aa3552b029d9b3241bb46b4df91159161c8
|
|
BLAKE2b-256 checksum How to use checksums |
b4dffffbef4fe45d17adead3a68fb56507b701d560cc62208d2f586f7ccb6451
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.
Transparency logSecurity for mixle-discrete 0.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mixle_discrete-0.7.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.