"""Reality branch representation (MERCURIAL B)."""
from typing import List, Optional
import numpy as np
from mercurial.core.patterns import Pattern
from mercurial.core.state_space import StateVector
[docs]
class RealityBranch:
"""A single reality branch B_a."""
[docs]
def __init__(self, branch_id: int, label: str = "", level: int = 7):
"""
Parameters
----------
branch_id : int
Unique identifier.
label : str
Descriptive name.
level : int
LADDER hierarchical level (0-18) where this branch primarily operates.
Default 7 (macroscopic material patterns).
"""
self.id = branch_id
self.label = label
self.level = level
self.global_pattern: Optional[Pattern] = None
self.history: List[Pattern] = []
self.entropy_profile: List[float] = []
self._custom_energy = None
self._custom_entropy = None
self._dpr_mode = False
self._is_conscious = False
self._is_impression = False
self.state_vector: Optional[StateVector] = None
self.decoherence_history: List[float] = []
[docs]
def set_global_pattern(self, pattern: Pattern):
self.global_pattern = pattern
self.history.append(pattern)
[docs]
def compute_entropy(self) -> float:
if self._custom_entropy is not None:
return self._custom_entropy
if self.global_pattern is None:
return 10.0
return self.global_pattern.free_energy() / 10.0
[docs]
def similarity_to(self, other: "RealityBranch") -> float:
"""Branch similarity σ(B_a, B_b) (Definition 5.3)."""
if self.global_pattern is None or other.global_pattern is None:
return 0.0
# Isomorphism degree between macroscopic patterns
v1 = self.global_pattern.V.flatten()
v2 = other.global_pattern.V.flatten()
min_len = min(len(v1), len(v2))
if min_len == 0:
return 0.0
corr = np.corrcoef(v1[:min_len], v2[:min_len])[0, 1]
return max(0.0, corr)
[docs]
def set_state_vector(self, state_vector: StateVector):
self.state_vector = state_vector
[docs]
def compute_orthogonality(self, other: "RealityBranch") -> float:
from mercurial.branches.decoherence import DecoherenceMeasure
if self.state_vector is None or other.state_vector is None:
return 1.0
dm = DecoherenceMeasure()
return dm.orthogonality(self.state_vector, other.state_vector)