Skip to main content

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.2.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

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

qbitnum-0.1.2-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file qbitnum-0.1.2.tar.gz.

File metadata

  • Download URL: qbitnum-0.1.2.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

Hashes for qbitnum-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d510097d5e5d434a5536d556d11a5eb93a52821b757179d2c7b0538c3fdc1942
MD5 9004748ec84b3bf6c0ec2f8f3321b03a
BLAKE2b-256 71fcecfd2ed265f12cb437cca618427e636bbb7af8cc07ea0b5c3b5182c37022

See more details on using hashes here.

File details

Details for the file qbitnum-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: qbitnum-0.1.2-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

Hashes for qbitnum-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8e1052aa639a53de2af1c099fa4e39ad1c848830d9f834701782464a11ef4d24
MD5 8b8df4a8075ac454cd7d417ec89c1be2
BLAKE2b-256 22665a9c2a2a5fb51aa4296536360f5708e162eb5657bd6418edbb39ca21aa01

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