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.1.tar.gz
(2.5 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.1.tar.gz.
File metadata
- Download URL: qbitnum-0.1.1.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b9f77206ec8e6f52878382d746ba551a24e8f796857046eaf0e7006a19d8b91
|
|
| MD5 |
dc7cd10a7b2e4739aa039351c3382590
|
|
| BLAKE2b-256 |
ac0a05a97499e616050c1a469360a618088f01d0ba7b492251906452d4f5511c
|
File details
Details for the file qbitnum-0.1.1-py3-none-any.whl.
File metadata
- Download URL: qbitnum-0.1.1-py3-none-any.whl
- Upload date:
- Size: 2.7 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 |
af66609cd3717a29a687fd1013f2be8cbc696c55dc32cf1e7af1b1b1521cc162
|
|
| MD5 |
23d19f094b6dc96b5115743349e7649d
|
|
| BLAKE2b-256 |
028f17a78ab0c47fd6c2d675d6e08661a28f15e694c551dfc4c6982e053c7c54
|