interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / src / omega_numeric_transc.h

71 lines · 3496 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * omega_numeric_transc.h -- E1 WP-B: frozen FP32 transcendental sequences,
19 * CPU tier, under the bounded contract.
20 *
21 * Contract (full text: docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md):
22 * - FP32 in, FP32 out. Every op is a fixed sequence of IEEE binary32
23 * instructions (FADD, FSUB, FMUL, FMADD, FDIV, FSQRT), integer operations
24 * and comparisons, written as explicit AArch64 instructions so the
25 * compiler cannot contract, reassociate or re-round anything. No libm,
26 * no long double, no double inside a sequence.
27 * - Required FP environment: FPCR round to nearest even, no flush to zero,
28 * no default NaN, no FEAT_AFP controls (OMEGA_NUMERIC_FPCR_REQUIRED_CLEAR).
29 * - Determinism: bit-identical output for every input on every run.
30 * - Cross-substrate parity: a future realization (GB10 or other) must
31 * reproduce these sequences bit for bit; the full-domain output digests
32 * in the contract are the parity target.
33 * - Error: integer ulp distance from the correctly rounded result (see the
34 * contract), bounded by OMEGA_TRANSC_MAX_ULP_* below and checked over all
35 * 2^32 inputs by tests/test_omega_transc.c (full mode).
36 * - NaN results are the canonical quiet NaN 0x7fc00000.
37 *
38 * These ops are not registered in the OMEGA_NOP table yet.
39 */
40#ifndef OMEGA_NUMERIC_TRANSC_H
41#define OMEGA_NUMERIC_TRANSC_H
42
43#include <stdint.h>
44
45/* Declared maximum ulp distance from the correctly rounded result:
46 * observed maximum over all 2^32 inputs + 1 ulp margin (RSQRT: correctly
47 * rounded by construction, observed 0, no margin). */
48#define OMEGA_TRANSC_MAX_ULP_SIGMOID 3u /* observed 2 */
49#define OMEGA_TRANSC_MAX_ULP_TANH 3u /* observed 2 */
50#define OMEGA_TRANSC_MAX_ULP_RSQRT 0u /* correctly rounded, observed 0 */
51#define OMEGA_TRANSC_MAX_ULP_EXP2 2u /* observed 1 */
52#define OMEGA_TRANSC_MAX_ULP_LOG2 2u /* observed 1 */
53#define OMEGA_TRANSC_MAX_ULP_ERF 3u /* observed 2 */
54#define OMEGA_TRANSC_MAX_ULP_SIN 2u /* observed 1, |x| <= 2^22 */
55#define OMEGA_TRANSC_MAX_ULP_COS 2u /* observed 1, |x| <= 2^22 */
56#define OMEGA_TRANSC_MAX_ULP_GELU 3u /* observed 2 */
57
58/* SIN/COS admitted domain: |x| <= 2^22. Outside it the result is NaN. */
59#define OMEGA_TRANSC_TRIG_MAX_ABS 4194304.0f
60
61float omega_math_sigmoid(float x); /* 1 / (1 + e^-x) */
62float omega_math_tanh(float x);
63float omega_math_rsqrt(float x); /* 1 / sqrt(x), correctly rounded */
64float omega_math_exp2(float x);
65float omega_math_log2(float x);
66float omega_math_erf(float x);
67float omega_math_sin(float x); /* |x| <= 2^22, else NaN */
68float omega_math_cos(float x); /* |x| <= 2^22, else NaN */
69float omega_math_gelu(float x); /* x * Phi(x) = x/2 * (1 + erf(x / sqrt 2)) */
70
71#endif