import { useEffect, useRef, useState } from "react"; import { Eye, Link2, Link2Off, RotateCcw } from "lucide-react"; import { gloss } from "../../lib/glossary"; import { applyCX, applyH2, measureOnce, mulberry32, probs, zero2, type State2, } from "../../lib/quantumToy"; import { TipIcon } from "../TipIcon"; import { BellRecipe } from "./BellRecipe"; import { Dial } from "./Dial"; import { PairGrid } from "./PairGrid"; import { useDrawLoop } from "./useDrawLoop"; /** * Step 3 — "Two qubits, one fate." The fixed Bell recipe (H on q0, * then CX — see BellRecipe for the wiring and for why "break the * link" swaps in H⊗H rather than just deleting CX) feeds one exact * two-qubit state; every look samples ONE four-way outcome and snaps * BOTH needles to its bits — with the link, always the same side * (the exact sim puts literally zero amplitude on 01/10, so "never a * disagreement" is a certainty claim, like step 2's H·H). Both * marginal dials read 50% in BOTH modes — that near-paradox is the * point: each qubit alone looks identical, only the JOINT tally * (the 2×2 grid) reveals the link. * * Seeded rng, reset on reset/toggle → every replay of a mode is * deterministic. Batch animation timing lives in useDrawLoop. The * seed is CHOSEN, not arbitrary: 20260703 opened with five 11s in a * row on the linked pair ("always the same side" read as "always * 11"); 20260708 gives 00 11 00 11… linked — both sides inside two * clicks — and a first-click disagreement (01) once broken. */ const SEED = 20260708; const EMPTY: Record = { "00": 0, "01": 0, "10": 0, "11": 0 }; function recipeState(broken: boolean): State2 { const mixed = applyH2(zero2(), 0); return broken ? applyH2(mixed, 1) : applyCX(mixed); } export function Step3Bell() { const [broken, setBroken] = useState(false); const [counts, setCounts] = useState>({ ...EMPTY }); const [snap, setSnap] = useState<[0 | 1, 0 | 1] | null>(null); const rng = useRef(mulberry32(SEED)); const unsnap = useRef | null>(null); useEffect( () => () => { if (unsnap.current) clearTimeout(unsnap.current); }, [], ); const settle = () => { if (unsnap.current) clearTimeout(unsnap.current); unsnap.current = setTimeout(() => setSnap(null), 380); }; const { running, run, stop } = useDrawLoop(() => { const bits = measureOnce(recipeState(broken), rng.current); setCounts((c) => ({ ...c, [bits]: (c[bits] ?? 0) + 1 })); setSnap([bits[0] === "1" ? 1 : 0, bits[1] === "1" ? 1 : 0]); settle(); }); const reset = () => { stop(); if (unsnap.current) clearTimeout(unsnap.current); setSnap(null); setCounts({ ...EMPTY }); rng.current = mulberry32(SEED); }; const toggleLink = () => { // Different distribution → fresh deterministic tally. setBroken((b) => !b); reset(); }; const state = recipeState(broken); const p = probs(state); const pQ0 = p[2] + p[3]; // P(q0 reads 1) — 50% in both modes const pQ1 = p[1] + p[3]; const total = Object.values(counts).reduce((a, b) => a + b, 0); const disagree = (counts["01"] ?? 0) + (counts["10"] ?? 0); return (

{broken ? "no link — each qubit mixes and answers alone" : "the second gate links them: whatever q0 answers, q1 must match"}

q0
q1

{total === 0 ? ( <>no looks yet — measure the pair to fill the grid ) : broken ? ( <> {total} look{total === 1 ? "" : "s"}:{" "} {disagree}{" "} disagreement{disagree === 1 ? "" : "s"} — no link, each qubit answers alone ) : ( <> {total} look{total === 1 ? "" : "s"}:{" "} 00 and{" "} 11 only — never a disagreement )}

); }