mirror of
https://github.com/blackboxprogramming/lucidia.git
synced 2026-03-17 05:57:21 -05:00
Synced from BlackRoad-OS-Inc/blackroad-operator/orgs/personal/lucidia BlackRoad OS — Pave Tomorrow. RoadChain-SHA2048: fe729062952871e7 RoadChain-Identity: alexa@sovereign RoadChain-Full: fe729062952871e77147cf6d938b799096e87d9024d7005a14c9e209e12e8ad0c825b624c7bc649fc7eeb4c284fdcab8231af77980065cc04d9f36fca479ffc2346ed3c1b73de6f240d8f9485f47c995ad5b81142f7179b84932c67914dff1c08db039349ba28fca36cb57688093bf0199268dd1c2f3448c9383000bc77cc9663066ff57b834370afc8838b18466ea9029908018b961555cccaabf2ce21649cf3cabc7f64bdcc4abdf2da259b210c342835a2cecf92bdd3b4e109b4d6e622f6934e13b2b123607bd61ce3d0f20454c9ab594f9284cffe18716619c52db57ce5f4ee2856cb96e1fa3748fe1fe65435bec297c5ab3ab58d570ec1064aea29931dd
73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
from __future__ import annotations
|
||
from dataclasses import dataclass
|
||
import math
|
||
from typing import Tuple
|
||
|
||
@dataclass
|
||
class BellState:
|
||
"""
|
||
Represents one of the four maximally entangled Bell states.
|
||
|
||
Attributes
|
||
----------
|
||
name : str
|
||
A human-readable label for the Bell state (e.g., "Φ+", "Ψ-").
|
||
coefficients : Tuple[complex, complex, complex, complex]
|
||
The amplitudes for the computational basis |00>, |01>, |10>, |11>.
|
||
"""
|
||
name: str
|
||
coefficients: Tuple[complex, complex, complex, complex]
|
||
|
||
def is_maximally_entangled(self) -> bool:
|
||
"""
|
||
Determine whether this state is maximally entangled.
|
||
|
||
For a Bell state, this checks that all nonzero coefficients have equal magnitude.
|
||
|
||
Returns
|
||
-------
|
||
bool
|
||
True if maximally entangled, False otherwise.
|
||
"""
|
||
non_zero = [abs(c) for c in self.coefficients if c != 0]
|
||
return len(non_zero) > 1 and len(set(non_zero)) == 1
|
||
|
||
|
||
def create_bell_state(index: int) -> BellState:
|
||
"""
|
||
Factory function to construct one of the four standard Bell states.
|
||
|
||
Parameters
|
||
----------
|
||
index : int
|
||
Index (0‑3) selecting among Φ+, Ψ+, Ψ-, Φ-.
|
||
|
||
Returns
|
||
-------
|
||
BellState
|
||
The requested Bell state.
|
||
|
||
Raises
|
||
------
|
||
ValueError
|
||
If the index is not between 0 and 3.
|
||
"""
|
||
inv_sqrt2 = 1 / math.sqrt(2)
|
||
coeffs = {
|
||
0: (inv_sqrt2, 0, 0, inv_sqrt2), # Φ+
|
||
1: (0, inv_sqrt2, inv_sqrt2, 0), # Ψ+
|
||
2: (0, inv_sqrt2, -inv_sqrt2, 0), # Ψ-
|
||
3: (inv_sqrt2, 0, 0, -inv_sqrt2), # Φ-
|
||
}
|
||
names = ["Φ+", "Ψ+", "Ψ-", "Φ-"]
|
||
if index not in coeffs:
|
||
raise ValueError("index must be in range 0‑3 to select a Bell state")
|
||
return BellState(name=names[index], coefficients=coeffs[index])
|
||
|
||
|
||
if __name__ == "__main__":
|
||
# Example usage: create each Bell state and check entanglement
|
||
for i in range(4):
|
||
bell = create_bell_state(i)
|
||
print(f"{bell.name}: coefficients = {bell.coefficients}, maximally entangled = {bell.is_maximally_entangled()}")
|