Parent macro-issue: #12
Goal
Create the surfface-geometry crate and establish the regression baseline that all subsequent phases depend on. Quadrance (WiringMetric::QuadranceGaussian) becomes the new default in LaplacianConfig; BhattacharyyaCosine is demoted to an explicit opt-in for legacy compatibility.
Why quadrance is the new default
The Bhattacharyya Coefficient kernel exponent already computes (μᵢ−μⱼ)²/(σᵢ²+σⱼ²) — a squared distance — and then applies exp(−·). The only sqrt calls in the current pipeline are in the k-NN gate (distance comparisons) and normalisation steps. Removing them:
- Is mathematically equivalent for all ordering-based operations (k-NN, MST, kernel weights).
- Eliminates ~10–15 % of floating-point work in the hot path.
- Makes every index build bit-reproducible across x86-64 and Apple Silicon (different SIMD sqrt implementations produce subtly different results today).
- Keeps the entire convergence and epiplexity theory intact — all theorems are stated in terms of squared distances inside kernels.
The switch is therefore a correctness upgrade, not a feature flag.
New crate: surfface-geometry
Create crates/surfface-geometry/ with the following public API:
/// Squared Euclidean distance — quadrance. Never takes a sqrt.
/// This is the canonical metric for all ArrowSpace distance computations.
pub fn quadrance(p: &[f32], q: &[f32]) -> f32;
/// Exact integer quadrance. Used in QuadranceRational mode (Phase 4).
pub fn quadrance_i64(p: &[i64], q: &[i64]) -> i64;
/// Triple Quad Formula collinearity predicate.
/// Returns true iff (Q1+Q2+Q3)² ≈ 2(Q1²+Q2²+Q3²) within eps.
/// Algebraically exact collinearity test — no trig, no sqrt.
pub fn tqf_collinear(q1: f64, q2: f64, q3: f64, eps: f64) -> bool;
/// Padé [2,2] rational approximation of exp(-x).
/// For x = Q/4t: approx = (1 - x/2 + x²/12) / (1 + x/2 + x²/12).
/// Used in QuadranceRational mode to keep edge weights in bounded-error rational arithmetic.
pub fn pade22_exp_neg(x: f64) -> f64;
WiringMetric enum
Add to LaplacianConfig in surfface-core:
#[derive(Debug, Clone, PartialEq)]
pub enum WiringMetric {
/// Quadrance Gaussian kernel: w_ij = exp(-Q(i,j) / 2σ²).
/// DEFAULT. Sqrt-free, numerically rigid, theoretically equivalent to BC kernel.
QuadranceGaussian { sigma_sq: f32 },
/// Full integer/rational arithmetic. Phase 4 deliverable.
/// Requires i16-quantised embeddings.
QuadranceRational { sigma_sq_num: i64, sigma_sq_den: i64 },
/// Legacy Bhattacharyya Coefficient kernel. Opt-in only.
/// Preserved for exact reproducibility of pre-Phase-0 indices.
BhattacharyyaCosine,
}
impl Default for WiringMetric {
fn default() -> Self {
WiringMetric::QuadranceGaussian { sigma_sq: 1.0 }
}
}
Regression baseline protocol
Before any Phase 1 work touches the hot path, the following property tests must all pass and be committed as the permanent regression suite:
Acceptance criteria
Parent macro-issue: #12
Goal
Create the
surfface-geometrycrate and establish the regression baseline that all subsequent phases depend on. Quadrance (WiringMetric::QuadranceGaussian) becomes the new default inLaplacianConfig;BhattacharyyaCosineis demoted to an explicit opt-in for legacy compatibility.Why quadrance is the new default
The Bhattacharyya Coefficient kernel exponent already computes
(μᵢ−μⱼ)²/(σᵢ²+σⱼ²)— a squared distance — and then appliesexp(−·). The only sqrt calls in the current pipeline are in the k-NN gate (distance comparisons) and normalisation steps. Removing them:The switch is therefore a correctness upgrade, not a feature flag.
New crate:
surfface-geometryCreate
crates/surfface-geometry/with the following public API:WiringMetricenumAdd to
LaplacianConfiginsurfface-core:Regression baseline protocol
Before any Phase 1 work touches the hot path, the following property tests must all pass and be committed as the permanent regression suite:
QuadranceGaussian(σ² calibrated to match BC bandwidth) andBhattacharyyaCosine. Edge set and Laplacian sparsity pattern must be identical.TauModeScore,FeatureSpectralScore, andFiedlerVectorScoredistributions must have KS-statistic < 0.01 between the two modes.QuadranceGaussianindex built on x86-64 and Apple Silicon must produce identical serialised bytes.BhattacharyyaCosinelocked: A golden-file test locks the BC output so any future regression is immediately visible.Acceptance criteria
surfface-geometrycrate compiles withcargo check --all-targets.WiringMetric::default()returnsQuadranceGaussian { sigma_sq: 1.0 }.CHANGELOG.mdentry: "quadrance is now the default wiring metric; BhattacharyyaCosine available as legacy opt-in".README.md: how to restore legacy behaviour withWiringMetric::BhattacharyyaCosine.