t27.aiРусский

GF1024: one kilobit

You will learn

The widest rung of the family, 1 + 391 + 632, and the test that names it.

GF1024 has 1024 bits: 1 sign, 391 exponent, 632 mantissa. Its ratio E / M is 0.6187, a distance of 0.0006 from 1 / phi, and the family spec has a test that names GF1024 as the format with the smallest phi distance. It is a rung of the family on paper; no hardware in this course computes in it.

Try it

Find PHI_DIST in gf1024.t27. Then in goldenfloat_family.t27 find the test about GF1024 and the function it calls.

Open the interactive lesson →

GoldenFloat 23: GF1024, one kilobit
GoldenFloat 23: GF1024, one kilobit ↗

GF1024: 1024 bits as the spec lays them out, read from gf1024.t27. Lesson 23 of the GoldenFloat course.

specs/numeric/gf1024.t27

// SPDX-License-Identifier: Apache-2.0
; gf1024.t27 -- GoldenFloat1024 Encode/Decode
; GF1024: 1024-bit floating point with 1 sign + 391 exponent + 632 mantissa
; Bit layout: [S(1) E(391) M(632)] = [1023:1023][1022:632][631:0]
; phi^2 + 1/phi^2 = 3 | TRINITY
; Generated by the closed-form rule e = round((N-1)/phi^2), m = N-1-e.
; STATUS: Conj (extrapolated; no RTL, no validated arithmetic).

module triformat-gf1024;

// ============================================================================
// Constants -- derived from the closed-form rule
// ============================================================================

pub const TOTAL_BITS : u16 = 1024;
pub const SIGN_BITS  : u8 = 1;
// W601: was `u8`, which cannot represent 391. The VALUE is right --
// round((1024-1)/phi^2) = 391 -- and every other rung's exponent width does fit
// in u8 (195, 97, 49, 36, 18), so this is the one place the annotation was
// copied without checking. Invisible until an invariant used the constant in
// arithmetic and forced the compiler to represent it.
pub const EXP_BITS   : u16 = 391;
pub const MANT_BITS  : u16 = 632;

pub const SIGN_SHIFT : u16 = 1023;
pub const EXP_SHIFT  : u16 = 632;
pub const MANT_SHIFT : u16 = 0;

; BIAS = 2^(390) - 1   -- multi-word constant (exceeds u64); see codegen
; EXP_MAX = 2^391 - 1   -- multi-word constant (exceeds u64)
pub const BIAS_EXPR    : str = "2^(391-1) - 1";
pub const EXP_MAX_EXPR : str = "2^391 - 1";

// E/M ratio (target: 1/phi ~ 0.6180339887)
pub const EM_RATIO   : f64 = 0.618670886076;
pub const PHI_DIST   : f64 = 0.000636897326;

pub const PHI_BIAS_STATUS : str = "OPEN -- not derivable from closed form; empirical per format";

// PHI_BIAS for this rung is NOT defined. The published formula
// PHI_BIAS = EXP_MAX - BIAS reproduces GF64 only and is RETRACTED as a general law.
// Do NOT invent a value via Fibonacci/Lucas/square coincidence; those are
// descriptive, not prescriptive.

// ============================================================================
// Invariants -- the Fpath below, made executable (W601)
//
// This file declared its own falsification path in a comment and nothing
// checked it. W600's per-test measurement found 38 specs that compile while
// asserting nothing; this is one, and the rule it is derived from is stated
// precisely enough to be a test.
// ============================================================================

invariant gf1024_field_widths_partition_the_word {
    @compileAssert(SIGN_BITS + EXP_BITS + MANT_BITS == TOTAL_BITS);
}

invariant gf1024_closed_form_mantissa {
    // m = N - 1 - e, the second half of the generating rule
    @compileAssert(MANT_BITS == TOTAL_BITS - 1 - EXP_BITS);
}

invariant gf1024_closed_form_exponent {
    // e = round((N-1)/phi^2)  <=>  (e - 1/2)*phi^2 <= N-1 <= (e + 1/2)*phi^2
    // Stated as bounds because the rule rounds; phi^2 = 2.618033988749895.
    @compileAssert((EXP_BITS as f64 - 0.5) * 2.618033988749895 <= TOTAL_BITS as f64 - 1.0);
    @compileAssert(TOTAL_BITS as f64 - 1.0 <= (EXP_BITS as f64 + 0.5) * 2.618033988749895);
}

invariant gf1024_shifts_follow_the_layout {
    @compileAssert(SIGN_SHIFT == TOTAL_BITS - 1);
    @compileAssert(EXP_SHIFT == MANT_BITS);
    @compileAssert(MANT_SHIFT == 0);
}

; ============================================================================
; Claim-status: Conj
; Fpath: any matched-substrate accuracy test (e.g. GF1024 vs binary1024/posit1024/takum1024)
;        where GF1024 fails to be parity-class or better falsifies this rung.
;        Note: dynamic range of phi^512 overflows binary1024 normalization at some n;
;        benchmarks MUST be normalised to in-range regimes.
; ============================================================================

Open the lesson's spec in the player ↗

All lessons