import { useEffect, useRef, useState } from "react"; import { Eye, RotateCcw, Wand2 } from "lucide-react"; import { gloss } from "../../lib/glossary"; import { applyH1, applyX1, measureOnce, mulberry32, zero1, type State1, } from "../../lib/quantumToy"; import { TipIcon } from "../TipIcon"; import { CircleState } from "./CircleState"; import { Tally } from "./Tally"; import { useDrawLoop } from "./useDrawLoop"; /** * Frame step 4 (of 7) — "The hidden direction". NOTE the file keeps * the spec name Step3Phase; component file names are stage names, * not frame positions (Step3Bell now sits at frame step 5). * * Act 1 — two circles side by side, prepared |+⟩ (recipe [H]) and * |−⟩ (recipe [X, H]); both dials cast the SAME 50/50 shadow. Every * look draws one outcome from EACH circle (seeded, exact sim), and * the two tallies scatter around fifty-fifty identically — the * DISTRIBUTIONS are identical (asserted in the node lane), so no * amount of measuring can tell the circles apart. (The tallies are * finite samples, so their counts differ draw to draw — the copy * says "twins to measurement", never "identical counts".) * * Act 2 — "apply H to both": left snaps to 0, right snaps to 1, * deterministically (H|+⟩ = |0⟩, H|−⟩ = |1⟩ exactly — sign * cancellation, the same interference that powers step 3's H·H). * A gate separates what measurement never could: the hidden * direction is real. Applying H resets the seeded tallies (new * distribution → fresh deterministic replay, the track-wide rule). * * Act 3 — THE SPHERE (PhaseSphere below): the honest full map. Our * gates walk one highlighted great circle of it; the sideways * directions are more of the same hidden dial (complex phase, which * the toy defers — see lib/quantumToy.ts header). */ const SEED = 20260713; const PLUS = applyH1(zero1()); // |+⟩ const MINUS = applyH1(applyX1(zero1())); // |−⟩ — computed from its shown recipe [X, H] const EMPTY = { "0": 0, "1": 0 }; export function Step3Phase() { const [hApplied, setHApplied] = useState(false); const [countsL, setCountsL] = useState>({ ...EMPTY }); const [countsR, setCountsR] = useState>({ ...EMPTY }); const [snapL, setSnapL] = useState<0 | 1 | null>(null); const [snapR, setSnapR] = useState<0 | 1 | null>(null); const rng = useRef(mulberry32(SEED)); const unsnap = useRef | null>(null); const left: State1 = hApplied ? applyH1(PLUS) : PLUS; const right: State1 = hApplied ? applyH1(MINUS) : MINUS; useEffect( () => () => { if (unsnap.current) clearTimeout(unsnap.current); }, [], ); const settle = () => { if (unsnap.current) clearTimeout(unsnap.current); unsnap.current = setTimeout(() => { setSnapL(null); setSnapR(null); }, 380); }; const { running, run, stop } = useDrawLoop(() => { const a = measureOnce(left, rng.current) === "1" ? 1 : 0; const b = measureOnce(right, rng.current) === "1" ? 1 : 0; setCountsL((c) => ({ ...c, [String(a)]: (c[String(a)] ?? 0) + 1 })); setCountsR((c) => ({ ...c, [String(b)]: (c[String(b)] ?? 0) + 1 })); setSnapL(a); setSnapR(b); settle(); }); const clearTallies = () => { stop(); if (unsnap.current) clearTimeout(unsnap.current); setSnapL(null); setSnapR(null); setCountsL({ ...EMPTY }); setCountsR({ ...EMPTY }); rng.current = mulberry32(SEED); }; const reset = () => { clearTallies(); setHApplied(false); }; const applyH = () => { if (hApplied || running) return; setHApplied(true); clearTallies(); // new distribution → fresh deterministic tally }; const totalL = (countsL["0"] ?? 0) + (countsL["1"] ?? 0); const total = totalL + (countsR["0"] ?? 0) + (countsR["1"] ?? 0); return (
{/* Acts 1 & 2 — the pair of circles */}
{[ { recipe: hApplied ? ["H", "H"] : ["H"], state: left, counts: countsL, snap: snapL, side: "left circle", }, { recipe: hApplied ? ["X", "H", "H"] : ["X", "H"], state: right, counts: countsR, snap: snapR, side: "right circle", }, ].map((c) => (
recipe {c.recipe.map((g, i) => ( {g} ))}
))}

{hApplied ? ( <> one H and they split:{" "} left swung to 0, right swung to 1 — with certainty. {" "} A gate told them apart; measurement never could. That difference is the hidden direction{" "} ) : total === 0 ? ( <> two recipes, two circles — same 50/50 shadow. Measure both: can any tally tell them apart? ) : ( <> after {totalL} look{totalL === 1 ? "" : "s"} each: both tallies scatter around fifty-fifty —{" "} to measurement these two states are twins … so try the extra H )}

{/* Act 3 — the sphere */}
the full map

The full map of one qubit is a sphere. Our gates walk the one highlighted circle of it — 0 on top, 1 at the bottom, plus-way and minus-way on the sides. The sideways directions are more of the same hidden dial: phase{" "} — every point on the equator casts the same 50/50 shadow, and only gates can tell them apart.

); } /** * Act 3's pseudo-3D sphere (SVG, no dependencies): orthographic * projection with a fixed ~18° downward tilt plus a user-controlled * spin φ around the vertical |0⟩–|1⟩ axis. Drag horizontally to * rotate; otherwise it slowly auto-rotates (~50s/turn) unless * prefers-reduced-motion, in which case it holds a fixed φ that * still shows depth. The great circle the lessons travel (the X–Z * meridian carrying |0⟩, |+⟩, |1⟩, |−⟩) is highlighted, split into a * solid front arc and a dashed back arc; a second, unlabeled faint * meridian and two latitude rings give the spin its depth cue — * they are the "more of the same hidden dial" the caption points at. */ const TAU = 0.32; // fixed tilt, radians const SR = 74; // sphere radius in viewBox units const SCX = 110; const SCY = 112; function project(x: number, y: number, z: number, phi: number) { // spin around the vertical (z) axis, then tilt about the screen x-axis const x1 = x * Math.cos(phi) + y * Math.sin(phi); const y1 = -x * Math.sin(phi) + y * Math.cos(phi); const up = z * Math.cos(TAU) + y1 * Math.sin(TAU); const depth = -z * Math.sin(TAU) + y1 * Math.cos(TAU); return { sx: SCX + SR * x1, sy: SCY - SR * up, front: depth <= 0, }; } /** A 3D circle → its front (solid) and back (dashed) polyline points. */ function arcs( pts: { sx: number; sy: number; front: boolean }[], ): { front: string[]; back: string[] } { const front: string[] = []; const back: string[] = []; let cf: string[] = []; let cb: string[] = []; for (const p of pts) { const s = `${p.sx.toFixed(1)},${p.sy.toFixed(1)}`; if (p.front) { if (cb.length > 1) back.push(cb.join(" ")); cb = []; cf.push(s); } else { if (cf.length > 1) front.push(cf.join(" ")); cf = []; cb.push(s); } } if (cf.length > 1) front.push(cf.join(" ")); if (cb.length > 1) back.push(cb.join(" ")); return { front, back }; } function PhaseSphere() { const reduced = typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches; const [phi, setPhi] = useState(reduced ? 0.55 : 0); const [dragging, setDragging] = useState(false); const lastX = useRef(0); useEffect(() => { if (reduced || dragging) return; const t = setInterval(() => setPhi((p) => p + 0.0063), 50); return () => clearInterval(t); }, [reduced, dragging]); // our great circle: the X–Z meridian, θ clockwise from |0⟩ const N = 72; const travel = arcs( Array.from({ length: N + 1 }, (_, i) => { const th = (2 * Math.PI * i) / N; return project(Math.sin(th), 0, Math.cos(th), phi); }), ); // depth cues: one faint sideways meridian (the hidden dial's plane) const side = arcs( Array.from({ length: N + 1 }, (_, i) => { const th = (2 * Math.PI * i) / N; return project(0, Math.sin(th), Math.cos(th), phi); }), ); // two latitude rings (spin-invariant ellipses — drawn directly) const lats = [0.55, -0.55].map((z0) => { const rho = Math.sqrt(1 - z0 * z0); return { cy: SCY - SR * z0 * Math.cos(TAU), rx: SR * rho, ry: SR * rho * Math.sin(TAU), }; }); const marks = [ { th: 0, t: "0", dx: 0, dy: -8 }, { th: Math.PI / 2, t: "+", dx: 10, dy: 3 }, { th: Math.PI, t: "1", dx: 0, dy: 15 }, { th: (3 * Math.PI) / 2, t: "−", dx: -10, dy: 3 }, ].map((m) => ({ ...m, ...project(Math.sin(m.th), 0, Math.cos(m.th), phi), })); return ( { e.currentTarget.setPointerCapture(e.pointerId); setDragging(true); lastX.current = e.clientX; }} onPointerMove={(e) => { if (!dragging) return; setPhi((p) => p + (e.clientX - lastX.current) / 90); lastX.current = e.clientX; }} onPointerUp={() => setDragging(false)} onPointerCancel={() => setDragging(false)} > {/* body + limb */} {/* latitude rings + sideways meridian — the "more sphere" texture */} {lats.map((l, i) => ( ))} {[...side.front, ...side.back].map((pts, i) => ( ))} {/* the vertical axis the shadow falls on */} {/* the great circle we travel: back dashed, front solid */} {travel.back.map((pts, i) => ( ))} {travel.front.map((pts, i) => ( ))} {/* the four states the lessons visit */} {marks.map((m) => ( {m.t} ))} drag to rotate ); }