@hotdocx/endash-kernel 0.1.0-preview.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/LICENSE +9 -1
  2. package/README.md +24 -2
  3. package/bin/endash-cli.cjs +4 -0
  4. package/bin/endash-mcp.cjs +7 -0
  5. package/browser.d.ts +44 -0
  6. package/endash-browser.js +698 -0
  7. package/index.cjs +704 -14
  8. package/index.d.ts +19 -11
  9. package/index.mjs +704 -14
  10. package/node.cjs +116606 -0
  11. package/node.d.ts +8 -0
  12. package/node.mjs +53 -0
  13. package/package.json +51 -7
  14. package/types/ast.d.ts +964 -0
  15. package/types/book/book_compiler.d.ts +57 -0
  16. package/types/book/html_renderer.d.ts +27 -0
  17. package/types/book/literate_en.d.ts +40 -0
  18. package/types/book/schema.d.ts +279 -0
  19. package/types/browser.d.ts +44 -0
  20. package/types/builders.d.ts +191 -0
  21. package/types/cache/core_snapshot.d.ts +259 -0
  22. package/types/cas/bar_hochschild.d.ts +106 -0
  23. package/types/cas/cotangent_deformation.d.ts +100 -0
  24. package/types/cas/cyclic_homology.d.ts +100 -0
  25. package/types/cas/derham_hkr.d.ts +117 -0
  26. package/types/cas/ext_algebra.d.ts +112 -0
  27. package/types/cas/groebner_syzygy.d.ts +43 -0
  28. package/types/cas/hilbert_proj_ag.d.ts +97 -0
  29. package/types/cas/hnf_snf.d.ts +49 -0
  30. package/types/cas/lefschetz_weil.d.ts +114 -0
  31. package/types/cas/localization_cech.d.ts +201 -0
  32. package/types/cas/matrix.d.ts +45 -0
  33. package/types/cas/modules_complexes.d.ts +141 -0
  34. package/types/cas/perm_coset_cgt.d.ts +166 -0
  35. package/types/cas/poly.d.ts +66 -0
  36. package/types/cas/reify_proofs.d.ts +104 -0
  37. package/types/cas/resolutions_spectral_seq.d.ts +193 -0
  38. package/types/cas/rings.d.ts +70 -0
  39. package/types/cas/smith_resultant_gauss.d.ts +164 -0
  40. package/types/cas/theta_stepanov.d.ts +182 -0
  41. package/types/check.d.ts +65 -0
  42. package/types/cli/endash_cli.d.ts +19 -0
  43. package/types/context.d.ts +110 -0
  44. package/types/duality.d.ts +76 -0
  45. package/types/elab/elab_ast.d.ts +274 -0
  46. package/types/elab/elaborate.d.ts +106 -0
  47. package/types/elab/env.d.ts +170 -0
  48. package/types/elab/match.d.ts +123 -0
  49. package/types/elab/pretty.d.ts +14 -0
  50. package/types/elab/structure.d.ts +46 -0
  51. package/types/elab/tactics.d.ts +238 -0
  52. package/types/elab/typeclass.d.ts +31 -0
  53. package/types/elab/unify.d.ts +166 -0
  54. package/types/eval.d.ts +28 -0
  55. package/types/index.d.ts +98 -0
  56. package/types/kernel_ops.d.ts +196 -0
  57. package/types/mcp/endash_mcp_server.d.ts +63 -0
  58. package/types/module/comparator.d.ts +86 -0
  59. package/types/module/desugar.d.ts +94 -0
  60. package/types/module/goal_inspector.d.ts +104 -0
  61. package/types/module/loader.d.ts +105 -0
  62. package/types/module/node_fs_provider.d.ts +26 -0
  63. package/types/module/package_builder.d.ts +83 -0
  64. package/types/module/proof_graph.d.ts +80 -0
  65. package/types/module/quasiquote.d.ts +37 -0
  66. package/types/module/stdlib_fresh_builders.d.ts +10 -0
  67. package/types/module/stdlib_tactic_hooks.d.ts +20 -0
  68. package/types/parser/lexer.d.ts +12 -0
  69. package/types/parser/parser.d.ts +78 -0
  70. package/types/parser/pratt.d.ts +17 -0
  71. package/types/parser/span.d.ts +26 -0
  72. package/types/parser/surface_ast.d.ts +501 -0
  73. package/types/stdlib_types.d.ts +113 -0
  74. package/types/value.d.ts +942 -0
@@ -0,0 +1,274 @@
1
+ /**
2
+ * Untrusted Surface AST & Structured Error Types for `endash` Elaboration.
3
+ *
4
+ * Strict Trust Boundary:
5
+ * All constructs in `endash/src/elab/*` are UNTRUSTED usability conveniences
6
+ * (implicit arguments, metavariables, namespaces, structures, typeclasses,
7
+ * pattern matching, and tactics). Every elaborated declaration must zonk to a
8
+ * 100% metavariable-free kernel `Term` / `CatTerm` and pass the trusted kernel
9
+ * typechecker (`checkTerm` / `declareDef` / `declareTheorem`).
10
+ */
11
+ import { CatTerm, Term, VarSym } from '../ast';
12
+ import { Duality, TransfMode } from '../duality';
13
+ export type EndashElabErrorCode = 'UNKNOWN_IDENT' | 'AMBIGUOUS_IDENT' | 'DUPLICATE_DECL' | 'UNIFICATION_MISMATCH' | 'META_OCCURS_CHECK' | 'META_SCOPE_ESCAPE' | 'META_NOT_PATTERN' | 'UNSOLVED_META' | 'PLICITY_MISMATCH' | 'EXPECTED_GRPD' | 'EXPECTED_FUNCTION' | 'EXPECTED_PAIR_OR_STRUCT' | 'EXPECTED_CAT' | 'EXPECTED_FUNCTOR' | 'EXPECTED_TRANSF' | 'EXPECTED_HOM_CELL' | 'LAX_DIAGONAL_FORBIDDEN' | 'TYPECLASS_MISSING' | 'TYPECLASS_AMBIGUOUS' | 'TYPECLASS_CYCLE' | 'TYPECLASS_FUEL_EXHAUSTED' | 'NON_EXHAUSTIVE_MATCH' | 'INVALID_MATCH_PATTERN' | 'SUBTYPE_EXT_REQUIRES_ISPROP' | 'TACTIC_FAILURE' | 'AXIOM_TAINTED' | 'DUPLICATE_TAG' | 'UNKNOWN_TAG';
14
+ export declare class EndashElabError extends Error {
15
+ readonly code: EndashElabErrorCode;
16
+ constructor(code: EndashElabErrorCode, message: string);
17
+ }
18
+ export type Plicity = 'explicit' | 'implicit' | 'instance';
19
+ export interface ElabBinder {
20
+ readonly name: string;
21
+ readonly plicity: Plicity;
22
+ /** Optional on lambdas and Pi binders; omitted types allocate a fresh `Grpd` hole. */
23
+ readonly ty?: ElabTerm;
24
+ }
25
+ export interface ElabArg {
26
+ readonly plicity?: Plicity;
27
+ /** Named override `(x := val)` matching a parameter binder by name. */
28
+ readonly name?: string;
29
+ readonly value: ElabTerm;
30
+ }
31
+ export type ElabCatTerm = {
32
+ readonly tag: 'ec-core';
33
+ readonly cat: CatTerm;
34
+ } | {
35
+ readonly tag: 'ec-term';
36
+ readonly term: ElabTerm;
37
+ } | {
38
+ readonly tag: 'ec-dual';
39
+ readonly dual: Duality;
40
+ readonly inner: ElabCatTerm;
41
+ } | {
42
+ readonly tag: 'ec-path';
43
+ readonly grpd: ElabTerm;
44
+ } | {
45
+ readonly tag: 'ec-product';
46
+ readonly fst: ElabCatTerm;
47
+ readonly snd: ElabCatTerm;
48
+ } | {
49
+ readonly tag: 'ec-functor';
50
+ readonly mode: TransfMode;
51
+ readonly dom: ElabCatTerm;
52
+ readonly cod: ElabCatTerm;
53
+ } | {
54
+ readonly tag: 'ec-hom';
55
+ readonly cat?: ElabCatTerm;
56
+ readonly src: ElabTerm;
57
+ readonly dst: ElabTerm;
58
+ };
59
+ export type ElabTerm = {
60
+ /** Local variable or namespace-resolved global symbol (`@name` sets `explicitAll: true`). */
61
+ readonly tag: 'e-ident';
62
+ readonly name: string;
63
+ readonly explicitAll?: boolean;
64
+ } | {
65
+ /** Direct hygienic bound variable reference for macro/tactic expansion. */
66
+ readonly tag: 'e-sym';
67
+ readonly sym: VarSym;
68
+ } | {
69
+ /** Metavariable hole `_` or named hole `?h`. */
70
+ readonly tag: 'e-hole';
71
+ readonly name?: string;
72
+ } | {
73
+ readonly tag: 'e-grpd-u';
74
+ readonly level: number;
75
+ } | {
76
+ readonly tag: 'e-strict-cat-u';
77
+ readonly level: number;
78
+ } | {
79
+ readonly tag: 'e-gray-cat-u';
80
+ readonly level: number;
81
+ } | {
82
+ readonly tag: 'e-empty';
83
+ } | {
84
+ readonly tag: 'e-unit';
85
+ } | {
86
+ readonly tag: 'e-tt';
87
+ } | {
88
+ readonly tag: 'e-bool';
89
+ } | {
90
+ readonly tag: 'e-bool-lit';
91
+ readonly value: boolean;
92
+ } | {
93
+ readonly tag: 'e-nat';
94
+ } | {
95
+ readonly tag: 'e-nat-lit';
96
+ readonly value: number;
97
+ } | {
98
+ readonly tag: 'e-circle';
99
+ } | {
100
+ readonly tag: 'e-sorry';
101
+ readonly label?: string;
102
+ } | {
103
+ readonly tag: 'e-sum';
104
+ readonly left: ElabTerm;
105
+ readonly right: ElabTerm;
106
+ } | {
107
+ readonly tag: 'e-list';
108
+ readonly elem: ElabTerm;
109
+ } | {
110
+ readonly tag: 'e-list-lit';
111
+ readonly elems: readonly ElabTerm[];
112
+ readonly elemTy?: ElabTerm;
113
+ } | {
114
+ readonly tag: 'e-pi';
115
+ readonly binders: readonly ElabBinder[];
116
+ readonly body: ElabTerm;
117
+ } | {
118
+ readonly tag: 'e-sigma';
119
+ readonly name: string;
120
+ readonly fst: ElabTerm;
121
+ readonly snd: ElabTerm;
122
+ } | {
123
+ readonly tag: 'e-lam';
124
+ readonly binders: readonly ElabBinder[];
125
+ readonly body: ElabTerm;
126
+ } | {
127
+ readonly tag: 'e-app';
128
+ readonly fn: ElabTerm;
129
+ readonly args: readonly ElabArg[];
130
+ } | {
131
+ readonly tag: 'e-let';
132
+ readonly name: string;
133
+ readonly ty?: ElabTerm;
134
+ readonly val: ElabTerm;
135
+ readonly body: ElabTerm;
136
+ } | {
137
+ readonly tag: 'e-ann';
138
+ readonly term: ElabTerm;
139
+ readonly ty: ElabTerm;
140
+ } | {
141
+ /** Identity type `lhs = rhs` with optional/inferred carrier type `ty`. */
142
+ readonly tag: 'e-eq';
143
+ readonly ty?: ElabTerm;
144
+ readonly lhs: ElabTerm;
145
+ readonly rhs: ElabTerm;
146
+ } | {
147
+ /** Reflexivity `rfl` with inferred carrier type and endpoint. */
148
+ readonly tag: 'e-refl';
149
+ readonly ty?: ElabTerm;
150
+ readonly val?: ElabTerm;
151
+ } | {
152
+ /** Anonymous constructor `⟨fst, snd⟩` for `Sigma` / `Prod` / `Subtype` / `Fin` / structures. */
153
+ readonly tag: 'e-pair';
154
+ readonly fst: ElabTerm;
155
+ readonly snd: ElabTerm;
156
+ } | {
157
+ /** Field / pair projection `target.fst`, `target.snd`, or `target.fieldName`. */
158
+ readonly tag: 'e-proj';
159
+ readonly target: ElabTerm;
160
+ readonly field: string;
161
+ } | {
162
+ /** Boolean `if cond then thenBr else elseBr`. */
163
+ readonly tag: 'e-if';
164
+ readonly cond: ElabTerm;
165
+ readonly thenBr: ElabTerm;
166
+ readonly elseBr: ElabTerm;
167
+ } | {
168
+ readonly tag: 'e-cat-obj';
169
+ readonly cat: ElabCatTerm;
170
+ } | {
171
+ /** Morphism carrier `Obj(Hom_C(src, dst))` with optional inferred `cat`. */
172
+ readonly tag: 'e-cat-hom';
173
+ readonly cat?: ElabCatTerm;
174
+ readonly src: ElabTerm;
175
+ readonly dst: ElabTerm;
176
+ } | {
177
+ /** Identity 1-cell `id_C(x)` with optional inferred `cat` and `obj`. */
178
+ readonly tag: 'e-cat-id';
179
+ readonly cat?: ElabCatTerm;
180
+ readonly obj?: ElabTerm;
181
+ } | {
182
+ /** Diagrammatic/categorical composition `comp(g, f) = g o f` with inferred endpoints. */
183
+ readonly tag: 'e-cat-comp';
184
+ readonly cat?: ElabCatTerm;
185
+ readonly g: ElabTerm;
186
+ readonly f: ElabTerm;
187
+ } | {
188
+ /** Object action `F.map0(x)` of a functor `F : Functor(A, B)`. */
189
+ readonly tag: 'e-cat-fapp0';
190
+ readonly fun: ElabTerm;
191
+ readonly obj: ElabTerm;
192
+ } | {
193
+ /** Morphism action `F.map1(p)` of a functor `F : Functor(A, B)` with inferred endpoints. */
194
+ readonly tag: 'e-cat-fapp1';
195
+ readonly fun: ElabTerm;
196
+ readonly src?: ElabTerm;
197
+ readonly dst?: ElabTerm;
198
+ readonly cell: ElabTerm;
199
+ } | {
200
+ /** Component `alpha.at(x)` of a transformation `alpha : Transf(mode, A, B, F, G)`. */
201
+ readonly tag: 'e-cat-tapp0';
202
+ readonly transf: ElabTerm;
203
+ readonly obj: ElabTerm;
204
+ } | {
205
+ /**
206
+ * Off-diagonal laxity `alpha.onCell(p)` for `mode = 'lax' | 'oplax'`.
207
+ * Fails closed with `LAX_DIAGONAL_FORBIDDEN` if misused as a bogus diagonal (`NC-1`).
208
+ */
209
+ readonly tag: 'e-cat-tapp1';
210
+ readonly mode?: TransfMode;
211
+ readonly transf: ElabTerm;
212
+ readonly src?: ElabTerm;
213
+ readonly dst?: ElabTerm;
214
+ readonly cell: ElabTerm;
215
+ } | {
216
+ /** Embedded raw kernel `Term`. */
217
+ readonly tag: 'e-core';
218
+ readonly term: Term;
219
+ };
220
+ export declare const E: {
221
+ ident: (name: string) => ElabTerm;
222
+ /** `@name` — suppresses automatic implicit/instance insertion (Lean `@f`). */
223
+ explicitRef: (name: string) => ElabTerm;
224
+ sym: (sym: VarSym) => ElabTerm;
225
+ hole: (name?: string) => ElabTerm;
226
+ grpd: (level?: number) => ElabTerm;
227
+ strictCat: (level?: number) => ElabTerm;
228
+ grayCat: (level?: number) => ElabTerm;
229
+ empty: () => ElabTerm;
230
+ unit: () => ElabTerm;
231
+ tt: () => ElabTerm;
232
+ bool: () => ElabTerm;
233
+ boolLit: (value: boolean) => ElabTerm;
234
+ nat: () => ElabTerm;
235
+ natLit: (value: number) => ElabTerm;
236
+ circle: () => ElabTerm;
237
+ sorry: (label?: string) => ElabTerm;
238
+ sum: (left: ElabTerm, right: ElabTerm) => ElabTerm;
239
+ list: (elem: ElabTerm) => ElabTerm;
240
+ listLit: (elems: readonly ElabTerm[], elemTy?: ElabTerm) => ElabTerm;
241
+ exp: (name: string, ty?: ElabTerm) => ElabBinder;
242
+ imp: (name: string, ty?: ElabTerm) => ElabBinder;
243
+ inst: (name: string, ty: ElabTerm) => ElabBinder;
244
+ pi: (binders: readonly ElabBinder[], body: ElabTerm) => ElabTerm;
245
+ arrow: (...types: readonly ElabTerm[]) => ElabTerm;
246
+ sigma: (name: string, fst: ElabTerm, snd: ElabTerm) => ElabTerm;
247
+ prod: (fst: ElabTerm, snd: ElabTerm) => ElabTerm;
248
+ lam: (binders: readonly ElabBinder[], body: ElabTerm) => ElabTerm;
249
+ fn: (names: readonly string[], body: ElabTerm) => ElabTerm;
250
+ app: (fn: ElabTerm | string, ...args: readonly (ElabTerm | ElabArg)[]) => ElabTerm;
251
+ namedArg: (name: string, value: ElabTerm) => ElabArg;
252
+ impArg: (value: ElabTerm) => ElabArg;
253
+ instArg: (value: ElabTerm) => ElabArg;
254
+ letIn: (name: string, val: ElabTerm, body: ElabTerm, ty?: ElabTerm) => ElabTerm;
255
+ ann: (term: ElabTerm, ty: ElabTerm) => ElabTerm;
256
+ eq: (lhs: ElabTerm, rhs: ElabTerm, ty?: ElabTerm) => ElabTerm;
257
+ rfl: (val?: ElabTerm, ty?: ElabTerm) => ElabTerm;
258
+ pair: (fst: ElabTerm, snd: ElabTerm) => ElabTerm;
259
+ tuple: (...items: readonly ElabTerm[]) => ElabTerm;
260
+ proj: (target: ElabTerm, field: string) => ElabTerm;
261
+ ifBool: (cond: ElabTerm, thenBr: ElabTerm, elseBr: ElabTerm) => ElabTerm;
262
+ catCore: (cat: CatTerm) => ElabCatTerm;
263
+ catTerm: (term: ElabTerm) => ElabCatTerm;
264
+ catPath: (grpd: ElabTerm) => ElabCatTerm;
265
+ catObj: (cat: ElabCatTerm) => ElabTerm;
266
+ hom: (src: ElabTerm, dst: ElabTerm, cat?: ElabCatTerm) => ElabTerm;
267
+ idCell: (obj?: ElabTerm, cat?: ElabCatTerm) => ElabTerm;
268
+ comp: (g: ElabTerm, f: ElabTerm, cat?: ElabCatTerm) => ElabTerm;
269
+ map0: (fun: ElabTerm, obj: ElabTerm) => ElabTerm;
270
+ map1: (fun: ElabTerm, cell: ElabTerm, src?: ElabTerm, dst?: ElabTerm) => ElabTerm;
271
+ tapp0: (transf: ElabTerm, obj: ElabTerm) => ElabTerm;
272
+ tapp1: (transf: ElabTerm, cell: ElabTerm, mode?: TransfMode) => ElabTerm;
273
+ core: (term: Term) => ElabTerm;
274
+ };
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Bidirectional Elaborator & Declaration Frontend for `endash`.
3
+ *
4
+ * Translates untrusted `ElabTerm` / `ElabCatTerm` expressions (with implicit `{x}`
5
+ * binders, `[C x]` typeclass constraints, holes `_`, named `(x := val)` overrides,
6
+ * `@explicit` references, pair/structure projections, and implicit-endpoint
7
+ * `StrictCat` operations) into explicit, metavariable-free kernel `Term`s, then
8
+ * delegates final verification to the trusted kernel (`checkTerm`, `declareDef`,
9
+ * `declareTheorem`).
10
+ */
11
+ import { CatTerm, Term } from '../ast';
12
+ import { checkCat } from '../check';
13
+ import { VCat, VGrpd, Value } from '../value';
14
+ import { ElabBinder, ElabCatTerm, ElabTerm } from './elab_ast';
15
+ import { DefTransparency, ElabDeclInfo, ElabEnv, RegisteredBinder } from './env';
16
+ import { ElabSession, LocalVarEntry } from './unify';
17
+ export interface ElabResult {
18
+ readonly term: Term;
19
+ readonly tyTerm: Term;
20
+ readonly tyVal: VGrpd;
21
+ readonly val: Value;
22
+ }
23
+ export interface ElabDefOptions {
24
+ readonly name: string;
25
+ readonly binders?: readonly ElabBinder[];
26
+ readonly ty?: ElabTerm;
27
+ readonly body: ElabTerm;
28
+ readonly isInstance?: boolean;
29
+ readonly instanceClass?: string;
30
+ readonly priority?: number;
31
+ readonly isSimp?: boolean;
32
+ readonly transparency?: DefTransparency;
33
+ }
34
+ export interface ElabTheoremOptions {
35
+ readonly name: string;
36
+ readonly binders?: readonly ElabBinder[];
37
+ readonly ty: ElabTerm;
38
+ readonly proof: ElabTerm;
39
+ readonly isSimp?: boolean;
40
+ readonly priority?: number;
41
+ }
42
+ export interface ElabAxiomOptions {
43
+ readonly name: string;
44
+ readonly binders?: readonly ElabBinder[];
45
+ readonly ty: ElabTerm;
46
+ }
47
+ /**
48
+ * Materialize any `sorry` placeholders recorded during `session` as explicitly
49
+ * tracked kernel `axiom` declarations (`__sorry_N`) so the declaration still
50
+ * typechecks cleanly while `printAxioms` / `assertAxiomFree` catches it (`NC-9a`).
51
+ */
52
+ export declare function materializePendingSorries(session: ElabSession): void;
53
+ export declare function allocateSorryHole(session: ElabSession, locals: readonly LocalVarEntry[], expectedTy: VGrpd, label?: string): {
54
+ readonly term: Term;
55
+ readonly val: Value;
56
+ };
57
+ /**
58
+ * Solve all queued `[C ...]` typeclass goals in `session`.
59
+ * Runs multiple passes if solving one instance refines metavariables in another.
60
+ */
61
+ export declare function resolvePendingInstances(session: ElabSession, opportunistic?: boolean): void;
62
+ /**
63
+ * Elaborate a standalone `ElabTerm` in `env` (with optional expected `ElabTerm` type),
64
+ * discharge typeclass constraints, zonk all metavariables, and re-verify via the
65
+ * trusted kernel (`checkTerm` / `inferTerm`).
66
+ */
67
+ export declare function elaborateTerm(env: ElabEnv, surface: ElabTerm, expectedSurfaceTy?: ElabTerm): ElabResult;
68
+ /**
69
+ * Elaborate and kernel-verify a transparent global `def` in `env`.
70
+ */
71
+ export declare function elabDef(env: ElabEnv, opts: ElabDefOptions): ElabDeclInfo;
72
+ /**
73
+ * Elaborate and kernel-verify an opaque global `theorem` in `env`.
74
+ */
75
+ export declare function elabTheorem(env: ElabEnv, opts: ElabTheoremOptions): ElabDeclInfo;
76
+ /**
77
+ * Elaborate and kernel-verify a global `axiom` declaration in `env` (`NC-9a`).
78
+ */
79
+ export declare function elabAxiom(env: ElabEnv, opts: ElabAxiomOptions): ElabDeclInfo;
80
+ export declare function inferHeadClassName(tyTerm: Term): string | undefined;
81
+ export declare function elabGrpd(session: ElabSession, locals: readonly LocalVarEntry[], surface: ElabTerm): {
82
+ readonly term: Term;
83
+ readonly grpdVal: VGrpd;
84
+ readonly level: number;
85
+ };
86
+ export declare function elabCat(session: ElabSession, locals: readonly LocalVarEntry[], catSurface: ElabCatTerm): {
87
+ readonly catTerm: CatTerm;
88
+ readonly catVal: VCat;
89
+ };
90
+ export interface InferredRaw {
91
+ readonly term: Term;
92
+ readonly val: Value;
93
+ readonly tyVal: VGrpd;
94
+ readonly binderSpecs: readonly RegisteredBinder[];
95
+ }
96
+ export declare function inferElab(session: ElabSession, locals: readonly LocalVarEntry[], surface: ElabTerm, autoInstantiate: boolean): {
97
+ readonly term: Term;
98
+ readonly val: Value;
99
+ readonly tyVal: VGrpd;
100
+ };
101
+ export declare function inferElabRaw(session: ElabSession, locals: readonly LocalVarEntry[], surface: ElabTerm): InferredRaw;
102
+ export declare function checkElab(session: ElabSession, locals: readonly LocalVarEntry[], surface: ElabTerm, rawExpectedTy: VGrpd): {
103
+ readonly term: Term;
104
+ readonly val: Value;
105
+ };
106
+ export { checkCat };
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Untrusted Elaborator Environment (`ElabEnv`) for `endash`.
3
+ *
4
+ * Wraps the trusted kernel's acyclic `GlobalEnv` with usability metadata that
5
+ * never enters the trusted computing base:
6
+ * - Hierarchical namespaces (`Nat.*`, `List.*`, `withNamespace`, `openNamespace`)
7
+ * - Leading binder plicity signatures (`explicit` | `implicit` | `instance`)
8
+ * - Structure / class field metadata (supporting dot-projection `s.field`)
9
+ * - `@[instance]` provider registry & pluggable bounded synthesizer hook
10
+ * - `@[simp]` rewrite lemma registry
11
+ */
12
+ import { Term } from '../ast';
13
+ import { BunchedContext, GlobalDeclEntry, GlobalEnv } from '../context';
14
+ import { VGrpd, Value } from '../value';
15
+ import { Plicity } from './elab_ast';
16
+ export interface RegisteredBinder {
17
+ readonly name: string;
18
+ readonly plicity: Plicity;
19
+ }
20
+ export type ElabDeclKind = 'def' | 'theorem' | 'axiom' | 'ctor' | 'proj';
21
+ export type DefTransparency = 'reducible' | 'semireducible' | 'simpl_nomatch' | 'irreducible';
22
+ export interface ElabDeclInfo {
23
+ readonly fullName: string;
24
+ readonly kind: ElabDeclKind;
25
+ readonly binders: readonly RegisteredBinder[];
26
+ readonly typeTerm: Term;
27
+ readonly valueTerm?: Term;
28
+ readonly transparency?: DefTransparency;
29
+ readonly kernelEntry: GlobalDeclEntry;
30
+ }
31
+ export interface StructureFieldMeta {
32
+ readonly name: string;
33
+ readonly projFullName: string;
34
+ readonly isParentSubobject?: boolean;
35
+ }
36
+ export interface StructureInfo {
37
+ readonly fullName: string;
38
+ readonly isClass: boolean;
39
+ readonly ctorFullName: string;
40
+ readonly paramBinders: readonly RegisteredBinder[];
41
+ readonly fields: readonly StructureFieldMeta[];
42
+ readonly parentClassNames: readonly string[];
43
+ }
44
+ export interface InstanceEntry {
45
+ readonly declFullName: string;
46
+ readonly className: string;
47
+ readonly priority: number;
48
+ readonly order: number;
49
+ }
50
+ export interface SimpLemmaEntry {
51
+ readonly declFullName: string;
52
+ readonly priority: number;
53
+ readonly order: number;
54
+ }
55
+ export type CrossRefNamespace = 'tag' | 'book' | 'ha' | 'ega' | 'sga' | 'weil' | 'rh' | 'kerodon' | 'stacks' | 'cisinski' | 'mathlib' | 'symmetry' | 'vol0' | 'vol1' | 'vol2';
56
+ export interface CrossRefTagEntry {
57
+ readonly declFullName: string;
58
+ readonly namespace: CrossRefNamespace;
59
+ readonly code: string;
60
+ readonly title?: string;
61
+ }
62
+ /**
63
+ * Pluggable callback invoked by `elaborate.ts` to discharge pending `[C ...]`
64
+ * instance holes once `elab/typeclass.ts` is loaded.
65
+ */
66
+ export type InstanceSynthesizerHook = (env: ElabEnv, ctx: BunchedContext, localInstances: readonly {
67
+ readonly symId: number;
68
+ readonly name: string;
69
+ readonly ty: VGrpd;
70
+ }[], goalTy: VGrpd, parentSession?: unknown, seedLocals?: unknown) => Term;
71
+ export declare function registerDefaultInstanceSynthesizer(fn: InstanceSynthesizerHook): void;
72
+ export declare class ElabEnv {
73
+ private _globals;
74
+ private readonly _globalValMap;
75
+ private readonly _decls;
76
+ private readonly _irreducibleDefs;
77
+ private readonly _structures;
78
+ private readonly _classes;
79
+ private readonly _instances;
80
+ private readonly _simpLemmas;
81
+ private readonly _crossRefTags;
82
+ private readonly _nsStack;
83
+ private readonly _openNs;
84
+ private _nextOrder;
85
+ private _synthesizer;
86
+ constructor(init?: {
87
+ globals?: GlobalEnv;
88
+ globalValMap?: ReadonlyMap<number | string, Value>;
89
+ decls?: Map<string, ElabDeclInfo>;
90
+ structures?: Map<string, StructureInfo>;
91
+ classes?: Set<string>;
92
+ instances?: InstanceEntry[];
93
+ simpLemmas?: SimpLemmaEntry[];
94
+ crossRefTags?: CrossRefTagEntry[];
95
+ nsStack?: string[];
96
+ openNs?: string[];
97
+ nextOrder?: number;
98
+ synthesizer?: InstanceSynthesizerHook;
99
+ });
100
+ static empty(): ElabEnv;
101
+ /** O(1)-style shallow structural clone for isolated test/tactic branching. */
102
+ clone(): ElabEnv;
103
+ get globals(): GlobalEnv;
104
+ globalValueMap(): ReadonlyMap<string, Value>;
105
+ emptyContext(): BunchedContext;
106
+ setInstanceSynthesizer(fn: InstanceSynthesizerHook): void;
107
+ getInstanceSynthesizer(): InstanceSynthesizerHook | undefined;
108
+ get currentNamespace(): string;
109
+ qualifyName(name: string): string;
110
+ withNamespace<T>(ns: string, body: () => T): T;
111
+ openNamespace(ns: string): void;
112
+ withOpenNamespace<T>(ns: string, body: () => T): T;
113
+ tryGetDeclExact(fullName: string): ElabDeclInfo | undefined;
114
+ getDefTransparency(fullName: string): DefTransparency;
115
+ hasIrreducibleDefs(): boolean;
116
+ /**
117
+ * Resolve a raw or partially qualified name against:
118
+ * 1. Current namespace stack from innermost to outermost,
119
+ * 2. Exact root declaration name,
120
+ * 3. Opened namespaces (failing with `AMBIGUOUS_IDENT` if >1 distinct target matches).
121
+ */
122
+ resolveDecl(rawName: string): ElabDeclInfo;
123
+ commitVerifiedDecl(nextGlobals: GlobalEnv, info: Omit<ElabDeclInfo, 'kernelEntry'>): ElabDeclInfo;
124
+ registerStructureInfo(info: StructureInfo): void;
125
+ getStructureInfo(name: string): StructureInfo | undefined;
126
+ allStructures(): ReadonlyMap<string, StructureInfo>;
127
+ isClass(fullName: string): boolean;
128
+ registerInstance(declFullName: string, className: string, priority?: number): void;
129
+ getInstancesForClass(className: string): readonly InstanceEntry[];
130
+ getAllInstances(): readonly InstanceEntry[];
131
+ registerSimpLemma(declFullName: string, priority?: number): void;
132
+ getSimpLemmas(): readonly SimpLemmaEntry[];
133
+ /**
134
+ * Register a Stacks/Book/HA/EGA cross-reference attribute (`NC-13c`):
135
+ * - Rejects unknown declarations (`UNKNOWN_IDENT`);
136
+ * - Rejects duplicate `(declFullName, namespace, code)` on the same declaration (`DUPLICATE_TAG`);
137
+ * - Enforces global uniqueness of `@[tag "XXXX"]` across distinct declarations (`DUPLICATE_TAG`).
138
+ */
139
+ registerCrossRefTag(declFullName: string, namespace: CrossRefNamespace, code: string, title?: string): void;
140
+ getTagsForDecl(declFullName: string): readonly CrossRefTagEntry[];
141
+ getAllCrossRefTags(): readonly CrossRefTagEntry[];
142
+ queryCrossRefTags(filter?: string, namespace?: CrossRefNamespace): readonly CrossRefTagEntry[];
143
+ lookupExactTag(codeOrSpec: string): readonly CrossRefTagEntry[];
144
+ declCount(): number;
145
+ allDecls(): ReadonlyMap<string, ElabDeclInfo>;
146
+ private _customTactics?;
147
+ private _sorryCounter;
148
+ nextSorryAxiomName(prefix?: string): string;
149
+ /**
150
+ * Return the sorted list of `axiom` names transitively used by `name` (`NC-9a`).
151
+ */
152
+ printAxioms(name: string): readonly string[];
153
+ /**
154
+ * Mechanically assert in O(1) that `name` depends on ZERO axioms or `sorry`s (`NC-9a`).
155
+ */
156
+ assertAxiomFree(name: string): void;
157
+ registerCustomTactic(name: string, handler: unknown): void;
158
+ registerTactic(name: string, handler: unknown): void;
159
+ getCustomTactic(name: string): unknown;
160
+ allCustomTactics(): ReadonlyMap<string, unknown>;
161
+ private _operators?;
162
+ setOperatorTable(tbl: unknown): void;
163
+ getOperatorTable(): unknown;
164
+ /**
165
+ * Merge an already kernel-verified imported `ElabEnv` into `this` idempotently
166
+ * (supporting diamond imports `A -> B, C -> D` while rejecting conflicting
167
+ * duplicate declarations across independent modules, `NC-9b`).
168
+ */
169
+ mergeImported(other: ElabEnv): void;
170
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Exhaustive 1- & 2-Scrutinee Structural Pattern-Match & Recursion Compiler.
3
+ *
4
+ * Compiles Lean-like pattern-matching and structural-recursion clauses over
5
+ * `Bool`, `Nat`, `Option` (`Sum Unit α`), `Sum`, `Prod`/`Sigma`, and `List`
6
+ * into explicit `boolElim`, `natElim`, `sumElim`, `listElim`, and pair
7
+ * projections — with full constructor-matrix exhaustiveness checking
8
+ * (`NON_EXHAUSTIVE_MATCH` / `INVALID_MATCH_PATTERN`) and curried `Pi` motives
9
+ * for simultaneous 2-argument recursion (`Nat.beq`, `List.zipWith`, `take`, etc.).
10
+ */
11
+ import { ElabTerm } from './elab_ast';
12
+ export type MatchTypeSpec = {
13
+ readonly kind: 'bool';
14
+ } | {
15
+ readonly kind: 'nat';
16
+ } | {
17
+ readonly kind: 'option';
18
+ readonly elemTy: ElabTerm;
19
+ } | {
20
+ readonly kind: 'sum';
21
+ readonly leftTy: ElabTerm;
22
+ readonly rightTy: ElabTerm;
23
+ } | {
24
+ readonly kind: 'prod';
25
+ readonly fstTy: ElabTerm;
26
+ readonly sndTy: ElabTerm;
27
+ } | {
28
+ readonly kind: 'list';
29
+ readonly elemTy: ElabTerm;
30
+ };
31
+ export declare const MType: {
32
+ bool: () => MatchTypeSpec;
33
+ nat: () => MatchTypeSpec;
34
+ option: (elemTy: ElabTerm) => MatchTypeSpec;
35
+ sum: (leftTy: ElabTerm, rightTy: ElabTerm) => MatchTypeSpec;
36
+ prod: (fstTy: ElabTerm, sndTy: ElabTerm) => MatchTypeSpec;
37
+ list: (elemTy: ElabTerm) => MatchTypeSpec;
38
+ };
39
+ export declare function matchTypeToElab(spec: MatchTypeSpec): ElabTerm;
40
+ export type Pat = {
41
+ readonly tag: 'p-wild';
42
+ readonly bind?: string;
43
+ } | {
44
+ readonly tag: 'p-bool';
45
+ readonly value: boolean;
46
+ } | {
47
+ readonly tag: 'p-zero';
48
+ } | {
49
+ readonly tag: 'p-succ';
50
+ readonly predBind: string;
51
+ } | {
52
+ readonly tag: 'p-none';
53
+ } | {
54
+ readonly tag: 'p-some';
55
+ readonly valBind: string;
56
+ } | {
57
+ readonly tag: 'p-inl';
58
+ readonly valBind: string;
59
+ } | {
60
+ readonly tag: 'p-inr';
61
+ readonly valBind: string;
62
+ } | {
63
+ readonly tag: 'p-pair';
64
+ readonly fstBind: string;
65
+ readonly sndBind: string;
66
+ } | {
67
+ readonly tag: 'p-nil';
68
+ } | {
69
+ readonly tag: 'p-cons';
70
+ readonly headBind: string;
71
+ readonly tailBind: string;
72
+ };
73
+ export declare const P: {
74
+ wild: (bind?: string) => Pat;
75
+ bool: (value: boolean) => Pat;
76
+ zero: () => Pat;
77
+ succ: (predBind: string) => Pat;
78
+ none: () => Pat;
79
+ some: (valBind: string) => Pat;
80
+ inl: (valBind: string) => Pat;
81
+ inr: (valBind: string) => Pat;
82
+ pair: (fstBind: string, sndBind: string) => Pat;
83
+ nil: () => Pat;
84
+ cons: (headBind: string, tailBind: string) => Pat;
85
+ };
86
+ export interface Match1Clause {
87
+ readonly pat: Pat;
88
+ readonly body: ElabTerm;
89
+ }
90
+ export interface CompileMatch1Options {
91
+ readonly scrutinee: ElabTerm;
92
+ readonly scrutineeType: MatchTypeSpec;
93
+ /** Motive `(x : ScrutTy) => ReturnTy` or constant `ReturnTy`. */
94
+ readonly returnTy: ElabTerm | ((scrutVar: ElabTerm) => ElabTerm);
95
+ readonly clauses: readonly Match1Clause[];
96
+ /** Optional name bound to the inductive hypothesis in `succ` / `cons` branches. */
97
+ readonly ihName?: string;
98
+ }
99
+ export declare function compileMatch1(opts: CompileMatch1Options): ElabTerm;
100
+ export interface Match2Clause {
101
+ readonly pat1: Pat;
102
+ readonly pat2: Pat;
103
+ readonly body: ElabTerm;
104
+ }
105
+ export interface CompileMatch2Options {
106
+ readonly scrutinee1: ElabTerm;
107
+ readonly type1: MatchTypeSpec;
108
+ readonly scrutinee2: ElabTerm;
109
+ readonly type2: MatchTypeSpec;
110
+ /** Return type `(s1, s2) => RetTy` or constant `RetTy`. */
111
+ readonly returnTy: ElabTerm | ((s1: ElabTerm, s2: ElabTerm) => ElabTerm);
112
+ readonly clauses: readonly Match2Clause[];
113
+ /**
114
+ * Optional name bound to the outer inductive hypothesis in `s1`'s step case
115
+ * (`succ` / `cons`), with curried type `(s2 : T2) -> RetTy(s1_pred, s2)`.
116
+ */
117
+ readonly ih1Name?: string;
118
+ }
119
+ export declare function compileMatch2(opts: CompileMatch2Options): ElabTerm;
120
+ export declare function buildNatSuccSurface(pred: ElabTerm): ElabTerm;
121
+ export declare function buildInlSurface(leftTy: ElabTerm, rightTy: ElabTerm, val: ElabTerm): ElabTerm;
122
+ export declare function buildInrSurface(leftTy: ElabTerm, rightTy: ElabTerm, val: ElabTerm): ElabTerm;
123
+ export declare function buildConsSurface(elemTy: ElabTerm, head: ElabTerm, tail: ElabTerm): ElabTerm;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Human-Readable Pretty-Printer for `endash` Semantic Values, Types & Terms.
3
+ *
4
+ * Used by unification errors, typeclass diagnostics, and tactic goal states to
5
+ * display Lean-like syntax (`[]`, `[1, 2]`, `x :: xs`, `A -> B`, `A × B`, `?m1`).
6
+ */
7
+ import { CatTerm, Term } from '../ast';
8
+ import { VCat, VGrpd, VNeutral, Value } from '../value';
9
+ export declare function prettyGrpd(rawG: VGrpd, depth?: number): string;
10
+ export declare function prettyCat(cat: VCat, depth?: number): string;
11
+ export declare function prettyVal(rawV: Value, depth?: number): string;
12
+ export declare function prettyNeutral(ne: VNeutral, depth?: number): string;
13
+ export declare function prettyTerm(t: Term, depth?: number, maxDepth?: number): string;
14
+ export declare function prettyCatTerm(c: CatTerm): string;