Skip to main content

Algebraic embeddings for deterministic arithmetic in neural networks

Project description

FluxEM

Algebraic embeddings for deterministic arithmetic in neural networks.

PyPI version License: MIT

FluxEM encodes numbers into vector spaces where arithmetic operations become geometric transformations. Unlike learned embeddings, these are algebraically exact (up to floating-point precision).

Origins

This project emerged from an exploration of music theory and its unrealized connections to machine learning. Theorists like Paul Hindemith (The Craft of Musical Composition), George Lewis (improvisation and AI), and Milton Babbitt (set-theoretic approaches to pitch) developed sophisticated frameworks for understanding intervallic relationships - treating musical intervals as transformations in structured pitch spaces.

These ideas of embedding and intervallic relationships had not been fully mapped to modern ML and mathematics. FluxEM represents one attempt to bridge that gap: encoding numbers so that arithmetic operations correspond to geometric transformations in embedding space, just as musical intervals correspond to movements in pitch space.

Key Properties

Operation Embedding Space Identity
Addition Linear encode(a) + encode(b) = encode(a + b)
Subtraction Linear encode(a) - encode(b) = encode(a - b)
Multiplication Logarithmic log_mag(a) + log_mag(b) = log_mag(a * b)
Division Logarithmic log_mag(a) - log_mag(b) = log_mag(a / b)
Powers Logarithmic log_mag(a^n) = n * log_mag(a)

Installation

pip install fluxem

Quick Start

from fluxem import create_unified_model

# Create a model for all four basic operations
model = create_unified_model()

# Compute arithmetic expressions
print(model.compute("42+58="))    # 100.0
print(model.compute("6*7="))      # 42.0
print(model.compute("100/4="))    # 25.0
print(model.compute("1000-999=")) # 1.0

Extended Operations

from fluxem import create_extended_ops

ops = create_extended_ops()

# Powers and roots
print(ops.power(2, 10))   # 1024.0
print(ops.sqrt(16))       # 4.0
print(ops.cbrt(27))       # 3.0

# Exponentials and logarithms
print(ops.exp(1))         # 2.718...
print(ops.ln(2.718))      # ~1.0
print(ops.log10(1000))    # 3.0

Low-Level Encoder Access

from fluxem import NumberEncoder, LogarithmicNumberEncoder

# Linear encoder for addition/subtraction
linear = NumberEncoder(dim=256, scale=100000.0)
emb_a = linear.encode_number(42)
emb_b = linear.encode_number(58)
result = linear.decode(emb_a + emb_b)  # 100.0

# Logarithmic encoder for multiplication/division
log_enc = LogarithmicNumberEncoder(dim=256)
emb_x = log_enc.encode_number(6)
emb_y = log_enc.encode_number(7)
result = log_enc.decode(log_enc.multiply(emb_x, emb_y))  # 42.0

How It Works

Linear Embeddings (Addition/Subtraction)

Numbers are encoded as scalar multiples of a fixed unit direction:

encode(n) = (n / scale) * unit_direction

This ensures linearity: encode(a) + encode(b) = encode(a + b).

Logarithmic Embeddings (Multiplication/Division)

Numbers are encoded using their logarithm:

encode(n) = (log(|n|) / log_scale) * direction + sign(n) * sign_direction

Since log(a * b) = log(a) + log(b), multiplication becomes vector addition in this space.

Why FluxEM?

Traditional neural networks struggle with arithmetic because:

  1. They must learn arithmetic from examples
  2. They fail on out-of-distribution numbers
  3. They have no algebraic guarantees

FluxEM solves this by encoding arithmetic identities directly into the representation. The model achieves 100% accuracy on arithmetic because the answer is computed algebraically, not learned.

Requirements

  • Python >= 3.10
  • JAX >= 0.4.20
  • Equinox >= 0.11.0

License

MIT License - see LICENSE for details.

Citation

If you use FluxEM in your research, please cite:

@software{fluxem2025,
  author = {Bown, Hunter},
  title = {FluxEM: Algebraic Embeddings for Deterministic Arithmetic},
  year = {2025},
  url = {https://github.com/Hmbown/FluxEM}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fluxem-0.1.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fluxem-0.1.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file fluxem-0.1.0.tar.gz.

File metadata

  • Download URL: fluxem-0.1.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for fluxem-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a85998cf7d89cba614d727aa0348096a2083b3068b828371da95dff78343ff69
MD5 38f5ff49ac2bae92426aefe0bc7f02bb
BLAKE2b-256 581804f876630cb371e67730e1c401d6f8775c866376c08021ccc648241d6036

See more details on using hashes here.

File details

Details for the file fluxem-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fluxem-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for fluxem-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0004a19d204d23001d3f8e46cc50741f240d9931e37c751da38b39faa9392344
MD5 24c5002890496e5ffabc5a0c44ef071e
BLAKE2b-256 4af10ae94f7c5ad24c5d7345d87bee205453dc6c589fb94ab0270c0c4a24ec0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page