Balanced ternary arithmetic and multi-valued logic library
Project description
tritlib
Balanced ternary arithmetic and multi-valued logic library for Python.
What is balanced ternary?
Balanced ternary is a numeral system in base 3 where each digit (called a trit) takes values from {−1, 0, +1} instead of the conventional {0, 1, 2}. It allows representing negative numbers without a sign bit, and negation is as simple as inverting every trit. Donald Knuth called it "perhaps the prettiest number system of all."
Features
Trit— immutable single‑trit type with arithmetic and logic operatorsTrits— arbitrary‑length balanced ternary integersTryte— fixed‑width ternary words- Multiple ternary logic systems: Kleene (K3), Łukasiewicz (L3), Heyting (HT) and more
- Step‑by‑step arithmetic (carry propagation, partial products) for educational use
- Pure Python, no dependencies, type‑hinted
Installation
pip install tritlib
Quick start
from tritlib.trit import Trit, P, Z, N
# Create trits
t = Trit(1) # +1
print(t) # "+"
print(-t) # "-"
# Predefined constants
assert P == Trit(1)
assert Z == Trit(0)
assert N == Trit(-1)
Roadmap
-
Trittype with immutability, arithmetic, hashing - Trit‑level logic (Kleene K3)
-
Tritsarbitrary‑precision integers -
Trytefixed‑width words - Additional logic systems (L3, HT, BI3, Post)
- Conversion utilities (int, str, float, binary‑coded ternary)
- Educational step‑by‑step computation output
Development
git clone https://codeberg.org/newick_2/tritlib.git
cd tritlib
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
python -m pytest
License
MIT License — see LICENSE file for details.
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 tritlib-0.2.0.tar.gz.
File metadata
- Download URL: tritlib-0.2.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7365d5abe0bc609d088a4a7e5eb351763f182f7ea153453790c15a6c5389a12d
|
|
| MD5 |
2879a6b2751977bd7d7ad02a6b978726
|
|
| BLAKE2b-256 |
d3a2164d5870c27fc9e640d8df8e521908e2dfaac0fb6e4b8b9103d2918b3d67
|
File details
Details for the file tritlib-0.2.0-py3-none-any.whl.
File metadata
- Download URL: tritlib-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8655afcb6baa95f74f26f6e39a598336da031abefd7c9038b64260216467d48b
|
|
| MD5 |
1f207c5737501199e099f76fa065290c
|
|
| BLAKE2b-256 |
d914a1c8e953a9d615c6b9daf2734038f16851c0482678919ef9a4b36701587a
|