htmljava

TFP testing Bell and GHZ

 "import numpy as np


# =========================

# Global TFP parameters

# =========================


H = 132          # Handshake budget (Section 12.0, 14.3)

K = 12           # Node degree / icosahedral symmetry (Section 12.1)

phi = (1 + np.sqrt(5)) / 2  # Golden ratio


# Internal contributions to decoherence (Section 16.7.1a)

epsilon_branch = np.log(K) / H       # Branching cost per step (log of options / budget)

epsilon_phase   = 1.0 / (H * phi)    # Phase dispersion from icosahedral misalignment

epsilon_time    = 1.0 / H            # Temporal skew per step


GAMMA = epsilon_branch + epsilon_phase + epsilon_time



#GAMMA = 0.035          # decoherence per recursion step

PHASE_NOISE = 0.12     # phase jitter on shared path

N_RUNS = 20000         # Monte Carlo samples

ELL_STAR = 9           # proto-time / closure threshold (tunable)


np.random.seed(1)


# =========================

# Core TFP primitives

# =========================


def coherence(l):

    """Shared coherence from recursion depth"""

    return np.exp(-GAMMA * l)


def shared_phase():

    """Phase accumulated on shared recursion path"""

    return np.pi + np.random.normal(0, PHASE_NOISE)


def consensus_choice(weights):

    """Consensus exhaustion → one surviving path"""

    total = sum(weights)

    if total <= 0:

        return np.random.randint(len(weights))

    probs = [w / total for w in weights]

    return np.random.choice(len(weights), p=probs)


# =========================

# Bell (2-party) test

# =========================


def bell_run(l, alpha, beta):

    C = coherence(l)

    theta = shared_phase()


    # Correlation from shared phase interference

    E = C * np.cos(alpha - beta + theta)


    # Measurement outcomes via stochastic sign sampling

    p = (1 + E) / 2

    return 1 if np.random.rand() < p else -1


def bell_CHSH(l):

    angles = [

        (0, np.pi/8),

        (0, 3*np.pi/8),

        (np.pi/4, np.pi/8),

        (np.pi/4, 3*np.pi/8)

    ]


    Es = []

    for a, b in angles:

        vals = [bell_run(l, a, b) for _ in range(N_RUNS)]

        Es.append(np.mean(vals))


    return Es[0] + Es[1] + Es[2] - Es[3]


# =========================

# GHZ (3-party) test

# =========================


def ghz_run(l, bases):

    """

    bases: tuple like ('X','Y','Y')

    """

    C = coherence(l)


    # Closure probability decays faster than Bell

    p_closure = np.exp(-l / ELL_STAR)


    if np.random.rand() > p_closure:

        # No global closure → independent outcomes

        return np.random.choice([-1,1],3)


    # Shared phase only if closure exists

    theta = shared_phase()


    # Three-path interference weights

    amps = [

        C * np.cos(theta),

        C * np.cos(theta + 2*np.pi/3),

        C * np.cos(theta + 4*np.pi/3)

    ]


    winner = consensus_choice([abs(a) for a in amps])


    # Map to ±1 outcomes

    outcomes = np.random.choice([-1,1],3)

    parity = outcomes[0] * outcomes[1] * outcomes[2]


    # Enforce parity bias from closure (not deterministically)

    target = +1 if bases.count('Y') == 0 else -1

    if parity != target:

        outcomes[np.random.randint(3)] *= -1


    return outcomes


def ghz_S(l):

    settings = {

        'XXX': ('X','X','X'),

        'XYY': ('X','Y','Y'),

        'YXY': ('Y','X','Y'),

        'YYX': ('Y','Y','X')

    }


    E = {}

    for k, b in settings.items():

        prods = []

        for _ in range(N_RUNS):

            o = ghz_run(l, b)

            prods.append(o[0]*o[1]*o[2])

        E[k] = np.mean(prods)


    return E['XXX'] - E['XYY'] - E['YXY'] - E['YYX']


# =========================

# Run depth scan

# =========================


print("\nDepth | CHSH (Bell) | S_GHZ")

print("----------------------------")


for l in range(2, 146, 2):

    chsh = bell_CHSH(l)

    sghz = ghz_S(l)

    print(f"{l:>5} | {chsh:>10.3f} | {sghz:>6.3f}")

"


Results;

"Depth | CHSH (Bell) | S_GHZ

----------------------------

    2 |     -1.210 |  3.184

    4 |     -1.135 |  2.567

    6 |     -1.078 |  2.064

    8 |     -1.004 |  1.658

   10 |     -0.949 |  1.316

   12 |     -0.918 |  1.079

   14 |     -0.822 |  0.831

   16 |     -0.782 |  0.665

   18 |     -0.738 |  0.550

   20 |     -0.685 |  0.443

   22 |     -0.651 |  0.371

   24 |     -0.613 |  0.275

   26 |     -0.587 |  0.203

   28 |     -0.566 |  0.181

   30 |     -0.478 |  0.136

   32 |     -0.458 |  0.114

   34 |     -0.474 |  0.101

   36 |     -0.408 |  0.066

   38 |     -0.400 |  0.053

   40 |     -0.380 |  0.045

   42 |     -0.354 |  0.044

   44 |     -0.342 |  0.044

   46 |     -0.335 |  0.015

   48 |     -0.286 |  0.013

   50 |     -0.292 |  0.005

   52 |     -0.277 |  0.011

   54 |     -0.243 | -0.006

   56 |     -0.211 |  0.004

   58 |     -0.200 |  0.006

   60 |     -0.210 |  0.017

   62 |     -0.195 |  0.016

   64 |     -0.189 | -0.003

   66 |     -0.163 |  0.007

   68 |     -0.158 | -0.001

   70 |     -0.126 |  0.007

   72 |     -0.141 |  0.007

   74 |     -0.127 | -0.035

   76 |     -0.154 |  0.019

   78 |     -0.111 | -0.023

   80 |     -0.101 | -0.021

   82 |     -0.098 | -0.002

   84 |     -0.111 |  0.019

   86 |     -0.100 | -0.006

   88 |     -0.058 |  0.006

   90 |     -0.061 | -0.023

   92 |     -0.097 |  0.011

   94 |     -0.067 | -0.007

   96 |     -0.091 | -0.018

   98 |     -0.095 | -0.033

  100 |     -0.071 | -0.013

  102 |     -0.014 |  0.008

  104 |     -0.046 | -0.007

  106 |     -0.043 | -0.008

  108 |     -0.034 | -0.012

  110 |     -0.052 | -0.015

  112 |     -0.034 |  0.008

  114 |     -0.043 | -0.010

  116 |     -0.033 | -0.031

  118 |     -0.042 |  0.021

  120 |     -0.026 |  0.007

  122 |     -0.030 | -0.009

  124 |     -0.015 |  0.006

  126 |     -0.065 | -0.006

  128 |     -0.036 | -0.004

  130 |      0.001 | -0.012

  132 |     -0.026 | -0.005

  134 |     -0.028 |  0.002

  136 |      0.004 | -0.008

  138 |     -0.007 |  0.005

  140 |     -0.011 |  0.011

  142 |     -0.026 |  0.020

  144 |      0.002 | -0.026"

No comments:

Post a Comment