Skip to main content

Version Python Coverage Lean4 License Code style: black

Balansis

Balansis is a scientific and engineering Python library for workloads where plain floating-point arithmetic hides instability instead of making it explicit.

It is built around Absolute Compensation Theory (ACT): a numerical model that introduces structured runtime objects such as AbsoluteValue, ABSOLUTE, and EternalRatio, and exposes compensation directly in the API instead of silently discarding it.

Documentation | Quick Start | API Reference | Formal Verification | Examples | Benchmarks


What Problem Does Balansis Solve?

IEEE 754 floating-point arithmetic is fast and ubiquitous, but several failure patterns still matter in real systems:

  • large reductions lose small but meaningful residuals
  • catastrophic cancellation turns uncertain differences into misleading zeros
  • divide-by-zero handling is deferred to edge-case logic instead of the data model
  • financial and simulation pipelines often hide correction logic outside the core arithmetic API

Balansis is for cases where you want those edge conditions to be visible, structured, and auditable.

Why Was It Created?

Balansis was created to explore a stronger arithmetic interface for:

  • scientific computations with unstable reductions
  • long-running simulations with drift-sensitive accumulation
  • financial workflows that benefit from structural cancellation semantics
  • research pipelines that want a bridge from runtime code to formal proofs

Real-World Value First

1. Large-Scale Aggregation

sum([1e16, 1.0, -1e16])  # IEEE 754 / Python float
# 0.0
from balansis import AbsoluteValue as Bv, Operations

values = [
    Bv.from_float(1e16),
    Bv.from_float(1.0),
    Bv.from_float(-1e16),
]
result, compensation = Operations.sequence_sum(values)
# result == AbsoluteValue.from_float(1.0)
# compensation > 0.0

Why it matters: the small residual survives, and the API exposes that a meaningful correction was applied.

2. Catastrophic Cancellation

(1e16 + 1.0) - 1e16  # IEEE 754 / Python float
# 0.0
from balansis import AbsoluteValue as Bv, Operations

a = Bv.from_float(1e16)
b = Bv.from_float(-1e16)
result, compensation = Operations.compensated_add(a, b)

Why it matters: when precision loss is suspected at very large magnitudes, Balansis preserves an informative residual instead of always collapsing to a spurious exact zero.

3. Financial Cancellation

from decimal import Decimal
from balansis.finance.ledger import Ledger

ledger = Ledger()
ledger.post_entry("cash", Decimal("250.00"))
ledger.post_entry("cash", Decimal("-250.00"))

balance = ledger.balance()
# balance == ABSOLUTE

Why it matters: offsetting entries cancel structurally to the ACT identity, which is easier to reason about than burying bookkeeping semantics in plain float totals.

4. Division Edge Handling

1.0 / 0.0  # standard runtime edge case
# ZeroDivisionError
from balansis import AbsoluteValue, Operations

num = AbsoluteValue.from_float(6.0)
den = AbsoluteValue.from_float(2.0)
ratio, compensation = Operations.compensated_divide(num, den)

Why it matters: Balansis makes ratio structure explicit through EternalRatio for valid denominators and rejects an ABSOLUTE denominator directly instead of pretending that infinity-like behavior is a normal value.


Why Adopt Balansis?

  • Explicit compensation: low-level operations return both a result and a compensation factor
  • Structured edge handling: ratio and additive-identity behavior are part of the model, not scattered ad hoc checks
  • Research continuity: the repository includes a Lean4 formal layer for the public ACT theorem surface
  • Practical scope: core arithmetic, algebraic structures, linear algebra, finance helpers, and experimental subprojects

Install In 60 Seconds

pip install balansis

CLI / pipx install:

pipx install balansis
balansis --version
balansis doctor

Optional extras:

pip install balansis[plot]
pip install balansis[notebook]
pip install balansis[torch]
pip install balansis[all]

Supported Python versions: 3.10, 3.11, 3.12.

More install options: Installation Guide


Quick Start

from balansis import AbsoluteValue, Operations, ABSOLUTE

a = AbsoluteValue(magnitude=5.0, direction=1)
b = AbsoluteValue(magnitude=3.0, direction=-1)

result, compensation = Operations.compensated_add(a, b)

print(result)
print(compensation)
print(ABSOLUTE)

Continue with:


Documentation By Audience

Audience Start here Why
Decision makers Why Balansis Understand the problem, the value proposition, and where Balansis fits
Developers Quick Start Install the package and start using the runtime surface
Researchers Mathematics Explore ACT concepts, notation, and theorem-oriented material
Verification-oriented readers Formal Verification Review the Lean architecture and current proof status
Contributors Contributing Set up the repo, quality gates, and documentation workflow

Documentation Map


Formal Verification Status

Version 1.1.0 ships a compiled Lean4 formalization on Mathlib v4.28.0.

  • BalansisFormal is the constructive core
  • ACT is the public theorem facade
  • formal/ contains 0 axiom, 0 sorry, 0 admit
  • public theorem groups A1-A5, E1-E4, and S1-S3 are compiled as Lean theorems

Verification entrypoints:


Package Surface

Core areas currently present in the repository:

  • balansis.core
  • balansis.algebra
  • balansis.linalg
  • balansis.finance
  • balansis.numpy_integration
  • balansis.ml
  • balansis.sets

Reader-oriented API navigation starts here: API Reference


TNSIM

tnsim/ is a repository subproject for zero-sum infinite sets experimentation. It is maintained in the same repository, but it is not the main balansis package entrypoint.


Contributing

Contributions are welcome, but Balansis is maintained under a dual-license model. Before opening a substantial pull request, read:


License

Balansis is dual-licensed:

Commercial execution material:

Copyright (c) 2024-2026 Andrey Tikhonov (XTeam-Pro). All rights reserved.


Balansis is part of the StudyNinja-Eco ecosystem.

Download files

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

Source Distribution

balansis-1.1.0.tar.gz (88.2 kB view details)

Uploaded Source

Built Distribution

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

balansis-1.1.0-py3-none-any.whl (97.9 kB view details)

Uploaded Python 3

File details

Details for the file balansis-1.1.0.tar.gz.

File metadata

  • Download URL: balansis-1.1.0.tar.gz
  • Upload date:
  • Size: 88.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for balansis-1.1.0.tar.gz
Algorithm Hash digest
SHA256 729e08ebff189bfcbec0c1507abc1687673d803c873054e7f091df37dc14a2e6
MD5 716f6f3ff8820aac1f35afa15f82dc53
BLAKE2b-256 8b3c8caf9acb496efc338bc3bd672b92e3212853e1e600fe01bc21b967eba832

See more details on using hashes here.

File details

Details for the file balansis-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: balansis-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 97.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for balansis-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2445ae239cb21e48e5b267e5364e161cc6b89a0fbaef90160bf88bd3eae0b828
MD5 0fbb7165fe7d0e78d8c8ada5534bf817
BLAKE2b-256 ab4d20871d9592ed3d61b47a27e3c8ab44f8ad8655439d91664be510746ee24f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 files

1.0.0

2 files

0.5.1

2 files

0.5.0

2 files

0.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page