Skip to content

Phase 0: surfface-geometry crate scaffolding + quadrance-default regression baseline #13

Description

@Mec-iS

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:

  • Topology parity: Build the ArrowSpace index on the CVE corpus (N = 313 841, F = 384) with both QuadranceGaussian (σ² calibrated to match BC bandwidth) and BhattacharyyaCosine. Edge set and Laplacian sparsity pattern must be identical.
  • Score parity: TauModeScore, FeatureSpectralScore, and FiedlerVectorScore distributions must have KS-statistic < 0.01 between the two modes.
  • Bit-exact cross-platform: QuadranceGaussian index built on x86-64 and Apple Silicon must produce identical serialised bytes.
  • BhattacharyyaCosine locked: A golden-file test locks the BC output so any future regression is immediately visible.

Acceptance criteria

  • surfface-geometry crate compiles with cargo check --all-targets.
  • All four public functions have doc-tests.
  • WiringMetric::default() returns QuadranceGaussian { sigma_sq: 1.0 }.
  • All regression baseline tests pass on CI.
  • CHANGELOG.md entry: "quadrance is now the default wiring metric; BhattacharyyaCosine available as legacy opt-in".
  • Migration note in README.md: how to restore legacy behaviour with WiringMetric::BhattacharyyaCosine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions