File size: 2,847 Bytes
224e773 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | /*
* jordan.h — Jordan Spectral Transformer
* Stage 4: Eigendecomposition and stable attractor identification
*
* Mathematical framework:
*
* Density-matrix evolution: ρ' = φ⁻¹ U ρ U† + φ⁻² ρ
* φ = (1+√5)/2 (golden ratio)
* Fixed points: [U, ρ*] = 0 (commutation)
* Stable attractors: e ∘ e = e (idempotents)
* Routing decisiveness: λ₊ - λ₋ (spectral gap)
*/
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
HK_OK = 0,
HK_ERR_NULL = 1,
HK_ERR_ALLOC = 2,
} hk_status;
typedef struct {
double spectral_radius; /* max |λ| */
double stability_score; /* [0,1]: how quickly system decays */
int jordan_blocks; /* Number of Jordan blocks */
double gershgorin_radius; /* Upper bound on eigenvalue magnitudes */
double spectral_gap; /* λ₊ - λ₋: routing decisiveness */
double convergence_tolerance; /* Tolerance for fixed-point detection */
hk_status status;
} hk_jordan_features;
/**
* hk_jordan_transform — Compute spectral features of routing graph
*
* Eigendecomposes the adjacency matrix and extracts:
* - Spectral radius (largest |λ|)
* - Stability score (measure of decay)
* - Jordan block structure
* - Gershgorin circle radius
* - Spectral gap (λ₊ - λ₋)
*
* @param adj_matrix Adjacency matrix [dim x dim]
* @param dim Matrix dimension
* @return Features with status code
*/
hk_jordan_features hk_jordan_transform(double **adj_matrix, int dim);
/**
* hk_jordan_detect_fixed_point — Check if matrix is a fixed point
*
* A fixed point ρ* satisfies [U, ρ*] = 0 (commutes with evolution).
*
* @param matrix Input matrix [dim x dim]
* @param dim Matrix dimension
* @param tolerance Tolerance for commutation check
* @return 1 if fixed point detected, 0 otherwise
*/
int hk_jordan_detect_fixed_point(double **matrix, int dim,
double tolerance);
/**
* hk_jordan_converge_idempotent — Iterate to idempotent
*
* Repeatedly squares the matrix A until A² = A (idempotent).
* Stable routing attractors satisfy e ∘ e = e.
*
* @param matrix Input matrix [dim x dim]
* @param dim Matrix dimension
* @param max_iter Maximum iteration count
* @param tolerance Convergence tolerance
* @return Number of iterations to convergence, -1 if failed
*/
int hk_jordan_converge_idempotent(double **matrix, int dim,
int max_iterations,
double tolerance);
/**
* hk_jordan_print_features — Debug output
*/
void hk_jordan_print_features(hk_jordan_features feat);
#ifdef __cplusplus
}
#endif
|