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
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
//! Independent oracles: a second algorithm for a quantity a suite also computes the
//! ordinary way, so an assertion pins the mathematics rather than the implementation.
use RealField;
use ;
/// The corrected variance computed as `Σ_{i<j}(xᵢ − xⱼ)² / (n(n − 1))`.
///
/// This is the "demonstrably different algorithm" of the anti-circularity allow-list, not the
/// definition reordered. It never forms the mean, never forms a deviation from the mean, and is
/// quadratic where the definition is linear. Lagrange's identity supplies the equality:
///
/// ```text
/// Σ_{i<j} (xᵢ − xⱼ)² = n·Σᵢ xᵢ² − (Σᵢ xᵢ)² = n · Σᵢ (xᵢ − x̄)²
/// ```
///
/// so `Σᵢ(xᵢ − x̄)² / (n − 1) = Σ_{i<j}(xᵢ − xⱼ)² / (n(n − 1))`.
///
/// Checked by hand on `[1, 2, 3]`: the pair differences are 1, 2 and 1, whose squares sum to
/// `1 + 4 + 1 = 6`, over `n(n − 1) = 6`, giving 1. The definition agrees — mean 2, squared
/// deviations `1 + 0 + 1 = 2`, over `n − 1 = 2`, giving 1.