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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//! Kani bounded proof harnesses for kernel contracts.
//!
//! This module contains 45 `#[kani::proof]` harnesses that promote key
//! properties from Level 3 (statistically tested via proptest) to Level 4
//! (bounded mathematical proof for ALL inputs up to size N).
//!
//! All code here is behind `#[cfg(kani)]` and invisible to normal builds.
use activation;
use adamw;
use attention;
use batchnorm;
use cma_es;
use conv1d;
use cross_entropy;
use flash_attention;
use gated_delta_net;
use gqa;
use kmeans;
use layernorm;
use lbfgs;
use matmul;
use pagerank;
use rmsnorm;
use rope;
use silu_standalone;
use softmax;
use ssm;
use swiglu;
// ════════════════════════════════════════════════════════════════════════════
// Float transcendental stubs
// ════════════════════════════════════════════════════════════════════════════
/// Magnitude bound for harness inputs that feed products, sums or exponents.
///
/// "Finite for every finite input" is false for these kernels: Kani finds
/// inputs near `f32::MAX` whose dot products overflow to inf, and inf - inf
/// is NaN (#3140). Real activations sit far inside this bound, so a harness
/// states its precondition as `|x| <= ACT_BOUND` instead of `x.is_finite()`.
const ACT_BOUND: f32 = 1.0e4;
/// `x` is finite and within [`ACT_BOUND`].
/// Stub for `f32::exp` — models exp(x) for softmax after max-subtraction.
///
/// Softmax calls exp(x_i - max(x)), where x_i - max(x) ∈ (-∞, 0].
/// Therefore exp returns values in (0, 1]. The element where x_i = max(x)
/// gets exp(0) = 1.0 exactly. All others get values in (0, 1).
///
/// Soundness:
/// - Lean proves exp(x) > 0 for all x ∈ ℝ (Real.exp_pos)
/// - Lean proves exp(0) = 1 (Real.exp_zero)
/// - The upper bound 1.0 follows from x_i - max(x) ≤ 0 → exp(·) ≤ 1
/// Deterministic exp stand-in for EQUIVALENCE harnesses (PMAT-3140).
///
/// `stub_exp` draws a fresh `kani::any()` per call, so two code paths that each
/// call `exp` on the same argument see two unrelated values and an equivalence
/// assertion between them is refuted by the stub, not by the code. This stub is a
/// pure function of `x` (positive, like exp), so both paths see the same value
/// and the harness judges only the arithmetic around the call. It has no branch
/// and no division: a stub with both timed out at 600 s on 4 elements.
/// Stub for `f32::sqrt` — returns an arbitrary non-negative finite value.
/// Stub for `f32::ln` — returns an arbitrary finite value.
/// Stub for `f32::sin` — returns a value in [-1, 1].
/// Stub for `f32::cos` — returns a value in [-1, 1].
/// Stub for `f32::tanh` — returns a value in (-1, 1).
/// Stub for `f32::powf` — returns an arbitrary positive finite value.
/// Stub for `f32::powi` — returns an arbitrary finite value.
// Group A (Activation) + Group B (Normalization): 14 harnesses
include!;
// Group C (Gated + Positional + Loss) + Group D (Matrix + Attention): 14 harnesses
include!;
// Group E1 (Optimizer + Sequence): 7 harnesses
include!;
// Group E2 (Classical ML): 10 harnesses
include!;