HPC-Quantize / quhit_hexagram.h
CompressedGemma's picture
It's only calibrated for Gemma, atm.
07b428c verified
Raw
History Blame Contribute Delete
11.7 kB
/*
* quhit_hexagram.h β€” The Hexagram Quhit
*
* A new quantum primitive: the EDGE DUAL of the triality quhit.
*
* The standard (triality) quhit stores amplitudes on 6 VERTICES of
* the hexagon β€” the computational basis states |0⟩...|5⟩.
*
* The hexagram quhit stores amplitudes on 6 LINE SEGMENTS of the
* unicursal hexagram β€” the face diagonals of the cube projected along
* its body diagonal (1,1,1).
*
* The 6 hexagram lines (unicursal traversal order):
*
* β„“β‚€: diameter Eβ€”centerβ€”D (cyan, C face diagonals)
* ℓ₁: outer Dβ€”C (yellow, Y face diagonal)
* β„“β‚‚: diameter Cβ€”centerβ€”F (magenta, M face diagonals)
* ℓ₃: outer Fβ€”B (cyan, C face diagonal)
* β„“β‚„: diameter Bβ€”centerβ€”G (yellow, Y face diagonals)
* β„“β‚…: outer Gβ€”E (magenta, M face diagonal)
*
* Key properties:
* - Chirality is intrinsic: the unicursal path has a direction.
* The two orientations correspond to the two mirror tetrahedra
* inscribed in the cube.
* - Ξ”=0 is the native ground state (hexagram states encode the
* exotic S₆ automorphism structure naturally).
* - The H₆ transform (vertex ↔ hexagram) is derived from the
* body-diagonal projection of face diagonals β€” NOT the DFT₆.
*
* Vertex model: TrialityQuhit (amplitudes on points)
* Edge model: HexagramQuhit (amplitudes on paths)
* Duality: Kramers-Wannier, mediated by S₆ outer automorphism
*/
#ifndef QUHIT_HEXAGRAM_H
#define QUHIT_HEXAGRAM_H
#include <stdint.h>
#define HEX_D 6
/* ═══════════════════════════════════════════════════════════════════════
* CHIRALITY β€” Path orientation of the unicursal hexagram
* ═══════════════════════════════════════════════════════════════════════ */
#define CHIRALITY_POS (+1) /* ℓ₀→ℓ₁→ℓ₂→ℓ₃→ℓ₄→ℓ₅ = tetrahedron A */
#define CHIRALITY_NEG (-1) /* ℓ₅→ℓ₄→ℓ₃→ℓ₂→ℓ₁→ℓ₀ = tetrahedron B (mirror) */
/* ═══════════════════════════════════════════════════════════════════════
* LINE SEGMENT TYPES
* ═══════════════════════════════════════════════════════════════════════ */
#define LINE_DIAMETER 0 /* Passes through center (2 face diagonals merged) */
#define LINE_OUTER 1 /* Outer edge connecting adjacent hex vertices */
/* ═══════════════════════════════════════════════════════════════════════
* THE HEXAGRAM QUHIT
* ═══════════════════════════════════════════════════════════════════════ */
typedef struct {
/* 6 complex amplitudes β€” one per hexagram line segment */
double line_re[HEX_D];
double line_im[HEX_D];
/* Chirality: +1 (positive traversal) or -1 (mirror traversal) */
int chirality;
/* Cached vertex-basis representation (for interconversion) */
double vertex_re[HEX_D];
double vertex_im[HEX_D];
uint8_t vertex_dirty; /* 1 if vertex cache is stale */
/* Line metadata (static, set at init) */
/* line_type[k]: LINE_DIAMETER or LINE_OUTER */
/* line_color[k]: 0=C(cyan), 1=M(magenta), 2=Y(yellow) */
} HexagramQuhit;
/* ═══════════════════════════════════════════════════════════════════════
* H₆ TRANSFORM β€” The body-diagonal projection matrix
*
* H₆ converts vertex amplitudes β†’ hexagram-line amplitudes.
* H₆† converts hexagram-line amplitudes β†’ vertex amplitudes.
*
* Derivation: each hexagram line β„“β‚– is a specific combination of
* vertex states determined by which cube face diagonals project
* onto that line under the body-diagonal (1,1,1) projection.
*
* The matrix is syntheme-weighted: diameters combine antipodal
* vertex pairs (both diagonals of a face), outer edges combine
* adjacent vertex pairs (single diagonal connecting two faces).
*
* H₆ is UNITARY: H₆ Β· H₆† = I.
* H₆ is NOT the DFT₆ β€” it encodes geometry, not Fourier analysis.
* ═══════════════════════════════════════════════════════════════════════ */
/* The 6Γ—6 H₆ transform matrices (precomputed at init) */
extern double H6_re[HEX_D][HEX_D];
extern double H6_im[HEX_D][HEX_D];
extern double H6_adj_re[HEX_D][HEX_D]; /* H₆† (adjoint) */
extern double H6_adj_im[HEX_D][HEX_D];
/* ═══════════════════════════════════════════════════════════════════════
* LIFECYCLE
* ═══════════════════════════════════════════════════════════════════════ */
/* Initialize the H₆ transform tables. Call once at startup. */
void hexagram_init_tables(void);
/* Initialize to the "first line" state |β„“β‚€βŸ© with positive chirality */
void hexagram_init(HexagramQuhit *q);
/* Initialize from a standard-basis state vector via H₆ transform */
void hexagram_init_from_vertex(HexagramQuhit *q,
const double *vert_re, const double *vert_im,
int chirality);
/* Initialize to a specific hexagram line segment |β„“β‚–βŸ© */
void hexagram_init_line(HexagramQuhit *q, int k, int chirality);
/* ═══════════════════════════════════════════════════════════════════════
* NATIVE HEXAGRAM GATES β€” O(D) operations
* ═══════════════════════════════════════════════════════════════════════ */
/* Path shift: advance along the unicursal path by Ξ΄ segments.
* |β„“β‚–βŸ© β†’ |β„“_{(k+Ξ΄) mod 6}⟩
* This is DIAGONAL in hexagram basis β€” O(D).
* Ξ΄>0 = forward along chirality, Ξ΄<0 = backward. */
void hexagram_path_shift(HexagramQuhit *q, int delta);
/* Per-line phase gate: |β„“β‚–βŸ© β†’ e^{iΟ†β‚–}|β„“β‚–βŸ©
* Diagonal in hexagram basis β€” O(D). */
void hexagram_phase(HexagramQuhit *q, const double *phi_re, const double *phi_im);
/* Diameter phase: apply phase only to diameter lines (β„“β‚€,β„“β‚‚,β„“β‚„).
* This targets the "through-center" segments specifically. O(3). */
void hexagram_diameter_phase(HexagramQuhit *q, double phi_re, double phi_im);
/* Outer phase: apply phase only to outer lines (ℓ₁,ℓ₃,β„“β‚…). O(3). */
void hexagram_outer_phase(HexagramQuhit *q, double phi_re, double phi_im);
/* Chirality flip: reverse the path orientation.
* Corresponds to switching between the two mirror tetrahedra.
* |β„“β‚–, +⟩ β†’ |β„“_{5-k}, -⟩ (reversal + conjugation)
* This is an INVOLUTION: flip ∘ flip = identity. O(D). */
void hexagram_flip(HexagramQuhit *q);
/* Triad gate: simultaneous rotation of all 3 diameters.
* ℓ₀↔ℓ₂↔ℓ₄ (diameters cycle), ℓ₁↔ℓ₃↔ℓ₅ (outers cycle).
* This is the Ο†-image of triality_rotate. O(D). */
void hexagram_triad(HexagramQuhit *q);
/* Inverse triad. O(D). */
void hexagram_triad_inv(HexagramQuhit *q);
/* ═══════════════════════════════════════════════════════════════════════
* ENTANGLEMENT β€” Center-crossing interaction
*
* Two hexagram quhits can entangle through shared center crossings.
* The 3 diameters all pass through the center point β€” when two
* hexagram states have amplitude on overlapping diameters, they
* interfere at the crossing.
*
* This is the hexagrammatic analog of CZ: it couples the diameter
* amplitudes of both quhits while leaving outer amplitudes unchanged.
* ═══════════════════════════════════════════════════════════════════════ */
void hexagram_cross(HexagramQuhit *a, HexagramQuhit *b);
/* ═══════════════════════════════════════════════════════════════════════
* MEASUREMENT
* ═══════════════════════════════════════════════════════════════════════ */
/* Measure which hexagram line the state occupies.
* Returns outcome 0..5. Collapses state. */
int hexagram_measure(HexagramQuhit *q, uint64_t *rng_state);
/* Probability distribution over the 6 lines β€” no collapse. O(D). */
void hexagram_probabilities(const HexagramQuhit *q, double *probs);
/* ═══════════════════════════════════════════════════════════════════════
* INTERCONVERSION β€” Vertex model ↔ Edge model
*
* These use the H₆ transform to convert between the two dual
* representations. The conversion is exact (H₆ is unitary).
* ═══════════════════════════════════════════════════════════════════════ */
/* Ensure vertex cache is up-to-date (applies H₆†) */
void hexagram_ensure_vertex(HexagramQuhit *q);
/* Get read-only vertex amplitudes (ensures first) */
const double *hexagram_vertex_re(HexagramQuhit *q);
const double *hexagram_vertex_im(HexagramQuhit *q);
/* ═══════════════════════════════════════════════════════════════════════
* DIAGNOSTICS
* ═══════════════════════════════════════════════════════════════════════ */
/* Print hexagram state: line amplitudes + chirality */
void hexagram_print(const HexagramQuhit *q, const char *label);
/* Line metadata */
int hexagram_line_type(int k); /* LINE_DIAMETER or LINE_OUTER */
int hexagram_line_color(int k); /* 0=C, 1=M, 2=Y */
const char *hexagram_line_name(int k); /* e.g. "β„“β‚€ diam C" */
#endif /* QUHIT_HEXAGRAM_H */