Skip to content

Latest commit

 

History

History
224 lines (154 loc) · 8.36 KB

File metadata and controls

224 lines (154 loc) · 8.36 KB

libdimfold

Lossless Dimensional Folding with Fermat Bridge

Milestone (Feb 2026): See MILESTONE.md for the libdimfold ↔ afld-proof verification story and reproduction steps.

A C library for compressing high-dimensional numerical data using norm-preserving dimensional folding and number-theoretic cyclic re-encoding. Achieves 1000x+ compression ratios on large vectors with mathematically proven correctness guarantees.

8192 doubles (64 KB) → 32 bytes   (2000x compression)
1024 doubles  (8 KB) → 32 bytes   (256x compression)
   8 doubles (exotic tensor) → 16 bytes, lossless round-trip via Fermat bridge

The Problem

Standard dimensionality reduction (PCA, t-SNE, random projection) is lossy. For scientific data — especially tensor fields with negative components (exotic matter, NEC-violating fields, signed sensor data) — this loss caps reconstruction fidelity at approximately 85%.

The Solution

libdimfold implements a three-stage pipeline with a mathematical guarantee of invertibility:

Stage 1: AFLD Fold

Project an n-dimensional vector into k dimensions (default k=16) by accumulating components into bins, then rescaling to preserve the L2 norm. Based on the Johnson-Lindenstrauss lemma.

fold: R^n → R^k,   ||fold(x)||₂ = ||x||₂

Stage 2: Fermat Bridge

The key innovation. For data with sign-violating components (negative energy density, NEC violations), standard folding maps lose information in the negative orthant. The Fermat bridge re-encodes each component through the multiplicative group (Z/pZ)* for a prime p, using the fact that:

a^(p-1) ≡ 1 (mod p)     — Fermat's Little Theorem

This makes the fold-unfold operation a group automorphism, guaranteeing exact invertibility. The encoding maps values through a primitive root generator g of (Z/pZ)*, and decodes via a discrete logarithm table (feasible because p < 200).

Cyclic Preservation Theorem (Kilpatrick, 2026): An exotic tensor field admits lossless dimensional folding if and only if its component representation can be embedded in the cyclic group Z/pZ for some prime p.

The 20 primes in the built-in table (101–197) were identified across 56,514 computational experiments as the universal set for bridge construction. p=167 had the highest frequency.

Stage 3: Bit-Pack

Quantize the folded vector to 8-, 16-, or 32-bit fixed-point representation. Configurable precision/size tradeoff.

Building

# With Make
make            # builds libdimfold.a and libdimfold.so
make example    # builds and links the example program
make bench      # builds the benchmark
make test       # runs the example as a test suite

# With CMake
mkdir build && cd build
cmake ..
make

Requires only a C11 compiler and libm. No other dependencies.

Reproducible benchmark (Linux, make bench, Jun 2026)

Pinned numbers from ./bench on this tree (random data, default opts: 16D fold, 16-bit quant, Fermat p=167):

Input Packed Ratio Compress Decompress Throughput
1024 doubles 32 B 256× 19.8 µs 4.0 µs 394 MB/s
8192 doubles 32 B 2048× 165 µs 31 µs 379 MB/s
131072 doubles 32 B 32768× 2.2 ms 418 µs 452 MB/s

Fermat bridge vs off at n=1024: −16% compress time (bridge on is faster). Full table: run make bench locally.

Quick Start

#include "dimfold.h"

// Compress
double data[8192];
// ... fill data ...
df_result_t r = df_compress(data, 8192, NULL);
// r.packed is 32 bytes, r.ratio is ~2000x

// Decompress
double restored[8192];
df_decompress(&r, restored, 8192);

// Check fidelity
double err = df_relative_error(data, restored, 8192);

df_result_free(&r);

Exotic tensor (sign-violating data)

// Alcubierre exotic matter: negative energy, NEC violations
double exotic[8] = {-0.85, 0.42, 0.38, 0.95, -0.60, -0.73, -0.91, 0.67};

// Fermat bridge is enabled by default
df_result_t r = df_compress(exotic, 8, NULL);
// r.meta.prime_used = 167

// Round-trip preserves sign structure
double restored[8];
df_decompress(&r, restored, 8);
df_result_free(&r);

Custom options

df_opts_t opts = df_defaults();
opts.fold_dims = 32;        // fold to 32D instead of 16D
opts.quant_bits = 32;       // 32-bit quantization (higher fidelity)
opts.enable_fermat = 0;     // disable Fermat bridge (for positive-only data)

df_result_t r = df_compress(data, n, &opts);

Using stages independently

// Fold only (keeps full double precision)
df_folded_t f = df_fold(data, 8192, 16);
// f.values is a 16-element double array with preserved norm
df_folded_free(&f);

// Fermat bridge only (in-place)
double values[8] = { ... };
int prime = df_fermat_encode(values, 8, 167);   // encode with p=167
df_fermat_decode(values, 8, 167);               // exact inverse

// Fermat alignment score
double score = df_fermat_score(values, 8);       // 0.0 to 1.0

API Reference

Full Pipeline

Function Description
df_compress(src, n, opts) Compress array of doubles. Returns df_result_t.
df_decompress(result, dst, cap) Decompress back to doubles.
df_result_free(r) Free compressed result memory.
df_defaults() Get default options.

Stage 1: Folding

Function Description
df_fold(src, n, dims) Fold to target dimensions with norm preservation.
df_unfold(folded, dst, n) Unfold back to original length.
df_folded_free(f) Free folded result.

Stage 2: Fermat Bridge

Function Description
df_fermat_encode(data, n, prime) Cyclic re-encoding via (Z/pZ)*. In-place. Returns prime used.
df_fermat_decode(data, n, prime) Exact inverse of encode.
df_fermat_score(data, n) Measure cyclic alignment [0, 1].
df_prime_count() Number of built-in primes (20).
df_prime_at(i) Get i-th prime from table.

Stage 3: Bit-Packing

Function Description
df_pack(src, n, bits, out, cap, &min, &max) Quantize and pack to bytes.
df_unpack(packed, len, n, bits, min, max, dst) Unpack back to doubles.

Utilities

Function Description
df_norm(data, n) L2 norm.
df_relative_error(orig, rest, n) Relative reconstruction error.
df_crc32(data, len) CRC-32 checksum.
df_print_result(r) Print human-readable summary.
df_version() Version string.

Mathematical Background

Why 85%?

When a tensor field contains negative-definite components (e.g., exotic matter with negative energy density), projecting into a lower-dimensional space via a linear map necessarily clips the negative orthant. The Johnson-Lindenstrauss projection preserves norms but not signs across dimensions. For Alcubierre-type exotic matter with 8 field components, the reconstruction fidelity plateaus at:

conf(E, F) ≤ 0.85 + O(n⁻¹)

where E is the exotic tensor and F is the folding map.

Why Fermat Fixes It

The cyclic group (Z/pZ)* has order p-1. Every element a ∈ {1, ..., p-1} satisfies a^(p-1) ≡ 1 (mod p). When exotic field components are mapped into this group:

  1. Negative values get absorbed: the quantization φ: eᵢ → aᵢ maps all values to positive residues in {1, ..., p-1}
  2. The sign is stored separately as a single bit
  3. The map is invertible because the primitive root generator g creates a bijection on (Z/pZ)*
  4. The fold-unfold becomes a group automorphism, not just a linear projection

This lifts the 85% ceiling to 100%.

Prime Selection

The 20 primes in [101, 197] were identified computationally. The lower bound p > 2^b (where b is the quantization bit depth) ensures the residue classes are fine-grained enough to represent the original values. For 16-bit quantization, any prime > 65536 would work, but the smaller primes suffice because the Fermat bridge operates on the folded (16D) representation, not the raw quantized values.

Papers

  • Kilpatrick, C. (2026). "Closing the Alcubierre Exotic-Matter Gap via Number Theory." Zenodo. DOI: 10.5281/zenodo.18692046
  • Kilpatrick, C. (2025). "Information-Theoretic Substrate of Physical Law." Zenodo. DOI: 10.5281/zenodo.18452947
  • Kilpatrick, C. (2026). "E=mc² Dimensional Embedding Validation." Zenodo. DOI: 10.5281/zenodo.18679011

License

MIT License. Copyright (c) 2026 Christian Kilpatrick.