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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/// Lean 4 backend for the Aver transpiler.
///
/// Transpiles only pure core logic: functions without effects, type definitions,
/// verify blocks (as `example` proofs), and decision blocks (as comments).
/// Effectful functions and `main` are skipped.
pub
pub
// Crate-wide re-export: committed-lemma handling (`codegen::lemma_discovery`)
// and the law-auto rungs map Aver fn names to their Lean spelling through the
// same helper the program defs are emitted with, so a cited lemma references
// `decode` / `Run` / `++` exactly as generated.
pub use aver_name_to_lean;
// `law_auto` cites the prelude spec lemma names via `super::`; the
// `transpile*` entry points below drive the unified emitter.
pub use prelude_spec_lemmas_for_builtins;
/// `aver proof --explain` residual probe — turns an emitted main law theorem's
/// source lines into a normalization-only twin so Lean reports its residual
/// (`unsolved goals`). Used by the `--check` harness in the `aver` binary.
pub use ;
use generate_prelude;
use ;
use HashSet;
use crate;
use crate;
/// Statement-class channel for emitted law theorems.
///
/// `aver proof --check`'s `universal` metric must know, per law theorem,
/// whether the emitted STATEMENT is genuinely universal or bounded: for a
/// `when`-law over non-refinement-lifted givens, `law_theorem_prop` prepends
/// sampled-domain disjunction premises (`a = 0 ∨ a = 1 ∨ …`) — the theorem
/// then only claims the law on the finite sample domain, even when it is
/// proven by real tactics with a kernel-clean axiom profile. Refinement-lifted
/// `when`-laws drop those premises (the Subtype carries the invariant) and
/// stay genuinely universal.
///
/// Only the code that BUILDS the statement knows which premises it prepended,
/// so the emitter records the class as one structured marker comment per
/// emitted law theorem, preceding it in the generated `.lean` source
/// (self-contained artifact — the classification travels with the export):
///
/// ```text
/// -- aver:law-class <theorem_name> universal
/// -- aver:law-class <theorem_name> bounded-domain
/// ```
///
/// The checker (`lean_universal_proof` in the CLI) consumes these markers and
/// must NEVER re-derive the class from theorem names or by re-parsing
/// statements. A law theorem without a marker earns no universal credit
/// (fail-closed for stale/foreign export dirs).
pub const LAW_CLASS_MARKER_PREFIX: &str = "-- aver:law-class ";
/// Marker class tag: no sampled-domain premises — the `∀`-statement is the
/// law's genuine universal claim.
pub const LAW_CLASS_UNIVERSAL: &str = "universal";
/// Marker class tag: sampled-domain disjunction premises bound the statement
/// to the finite sample domain.
pub const LAW_CLASS_BOUNDED_DOMAIN: &str = "bounded-domain";
/// How verify blocks should be emitted in generated Lean.
// RecursionPlan / ProofModeIssue moved to shared `crate::codegen::recursion`
// so the Dafny backend can reuse the same classifier. Re-export here so
// existing `lean::RecursionPlan` / `lean::ProofModeIssue` call sites keep
// working without churn.
pub use crate;
pub use PROOF_FUEL_EXHAUSTED_MSG;
/// The marker every Lean runtime panic prints into captured build output.
/// Empirically pinned against real `lake build` transcripts (both panic
/// sites below produce it):
///
/// ```text
/// info: ././././FuelProbe.lean:27:0: PANIC at stepSum__fuel FuelProbe:8:9: Aver proof fuel exhausted
/// PANIC at stepSumAcc__fuel FuelProbe:19:9: Aver proof fuel exhausted
/// info: ././././PanicProbe.lean:11:0: PANIC at Char.toCode AverCommon:11:12: Char.toCode: string is empty
/// ```
///
/// (lake prefixes the first diagnostic of a build step with `info: <loc>:`,
/// later ones print raw — both carry `PANIC at `.)
pub const LEAN_PANIC_LINE_MARKER: &str = "PANIC at ";
/// Count model panic lines in captured `lake build` output.
///
/// Lean's `panic!` does NOT abort: at `native_decide` evaluation time it
/// prints `PANIC at <fn> <file>:<line>: <msg>` (to lake's captured output)
/// and returns the result type's `default` value. When BOTH sides of a
/// bounded sample route through the model (`verify f(x) => g(x)` cases,
/// every `_sample_N` / `_checked_domain` theorem), a panicking evaluation
/// reduces both sides to `default` and the kernel certifies a vacuous —
/// possibly FALSE — equation while `lake` exits 0 with zero sorries. The
/// panic line in the build output is the only trace, so `aver proof --check`
/// charges ANY hit as a hard failure.
///
/// Scans for the generic `PANIC at ` line marker, not a per-site message:
/// the emitted exports contain `panic!` only at compiler-generated sites —
/// the fuel wrappers' exhaustion arm ([`PROOF_FUEL_EXHAUSTED_MSG`]) and
/// partial prelude builtins (e.g. `Char.toCode` on an empty string) — and
/// every one of them shares the same panic-returns-`default` vacuity vector.
/// A green check has no legitimate panic, and the generic marker also
/// catches panics raised inside Lean's own stdlib (e.g. a `get!` deep in a
/// future prelude helper) that a per-message scan could never enumerate.
/// Counts matching LINES (one panic prints exactly one line; the same site
/// can fire on several theorems).
///
/// Known false-positive boundary, accepted: on an ALREADY-FAILING build, a
/// native_decide error can echo the false proposition, and a user string
/// literal containing `PANIC at ` inside it would inflate the count (and
/// set `model_panicked`). The verdict stays correct — the build already
/// failed on exit status — so a spurious match can only turn a red redder,
/// never a green red.
pub
pub
pub
pub
pub use cratesizeof_measure_param_indices;
/// Proof-mode diagnostics for Lean transpilation.
///
/// Returns human-readable notices for recursive shapes that still fall back to
/// regular `partial` Lean defs instead of total proof-mode emission.
/// Transpile an Aver program to a Lean 4 project.
///
/// Takes `&mut ctx` so it can run `ctx.refresh_facts()` upfront — keeps
/// the derived sets (`mutual_tco_members`, `recursive_fns`) in sync with
/// the current items + modules. Idempotent: production callers go through
/// `build_context` which already populated them, so refresh recomputes
/// the same answer; test stubs that build the ctx piecewise (push items
/// in-place, bypass `build_context`) get the fresh sets they need.
/// Proof-mode transpilation.
///
/// Uses recursion plans validated by `proof_mode_issues` and emits supported
/// recursive functions without `partial`, adding `termination_by` scaffolding.
/// Proof-mode transpilation for an artifact CERTIFICATE's reused model
/// modules.
///
/// Same model DEFINITIONS as [`transpile_for_proof_mode`], but emitted
/// without the proof-only executable machinery that the `aver proof`
/// sample checks rely on: the `@[implemented_by]`/`unsafe` `DecidableEq`
/// shims (user recursive types and `Float`), the `verify` sample-check
/// `example … := by native_decide` blocks, and the `@[simp]` string-prelude
/// spec lemmas. A certificate never elaborates those — it carries its own
/// decode-to-`Int`/bytes anti-vacuity guards — and the checker's
/// elaboration-executes-code wall rejects the `unsafe`/`implemented_by`/
/// `@[` tokens they contain. The mode drops them at the source so the
/// certificate's model data files stay kernel-clean, instead of stripping
/// them out of already-emitted text. The `aver proof` emission is
/// untouched (this is a distinct entry point).
/// Transpile an Aver program to a Lean 4 project with configurable verify proof mode.
///
/// - `NativeDecide` emits `example ... := by native_decide`
/// - `Sorry` emits `example ... := by sorry`
/// - `TheoremSkeleton` emits named theorem skeletons with `sorry`