Quantum‐inspired numeric data type for probabilistic arithmetic
Project description
qbitnum
Quantum‐Inspired Numeric Data Type for Classical Python
qbitnum provides a QBitNum class that simulates qubit‑like superposition for integer/float values, letting you perform probabilistic arithmetic in pure Python.
Features
- Store distributions of possible values with associated probabilities
- Support
+,-,*,//(and extendable) operations over superposed states - Post‑operation “collapse” in three modes:
- mean: expected value
- max: most likely value
- sample: random draw by probability
Installation
pip install qbitnum
from qbitnum import QBitNum
# Create superposed values
q1 = QBitNum([(1, 0.5), (2, 0.5)])
q2 = QBitNum([(3, 0.7), (4, 0.3)])
# Add them
q3 = q1 + q2
print(q3)
# QBitNum({4: 0.35, 5: 0.5, 6: 0.15})
# Collapse to a single value:
print(q3.collapse('mean')) # 4.8
print(q3.collapse('max')) # 5
print(q3.collapse('sample')) # 4 or 5 or 6 (random)
class QBitNum:
def __init__(self, states: List[Tuple[Number, float]]):
"""
states: list of (value, probability), probabilities need not sum to 1.
"""
def __add__(self, other: QBitNum) -> QBitNum: # likewise -, *, //
def collapse(self, mode: str = 'mean') -> Number
"""
mode in {'mean', 'max', 'sample'}
"""
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
qbitnum-0.1.3.tar.gz
(3.1 kB
view details)
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 qbitnum-0.1.3.tar.gz.
File metadata
- Download URL: qbitnum-0.1.3.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbac7383b33aa4abf8e95baca337916db00b0bb2fe17c9588dd248084afaceb9
|
|
| MD5 |
4bf09d0bd9ac45b10e4d9c1be7e143d0
|
|
| BLAKE2b-256 |
3147108853c4a04d8644214d59222555514cc8c1bc5991b99adc5e37aa71ecc5
|
File details
Details for the file qbitnum-0.1.3-py3-none-any.whl.
File metadata
- Download URL: qbitnum-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb692090ccf21f4f1777088a17164bd8dea56a4edbe6f45e37af812dc8dea89f
|
|
| MD5 |
7e2ed070e60349de6409e822ef6b0c54
|
|
| BLAKE2b-256 |
76cdfdf116a418267fa7eaf10a4518c4fdb40911d97f28d319694eca36371025
|