@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,182 @@
1
+ /**
2
+ * Phases R4 & R5 Browser-Safe Cyclotomic Discrete Poisson Summation, Quadratic Gauss Norms,
3
+ * Fock–Gram Positivity, Categorical Rallis Seesaw Duality (`by cas_theta`), &
4
+ * Characteristic-Free Stepanov Hasse-Jet Multiplicity Certifier (`by cas_stepanov`)
5
+ * (`endash/src/cas/theta_stepanov.ts`, `0` Node built-ins, `0` `src/stdlib/*` imports, `0` `any` casts).
6
+ *
7
+ * Certifies inside `src/check.ts`:
8
+ * 1. `ThetaAlg.ThetaSeesawCert [p, n, subStride] signal gramFlat seesawSpec [poissonVal, gaussNorm, gramDet, seesawVal]`:
9
+ * - Exact Discrete Poisson Summation `|H^\perp| \sum_{h \in H} f(h) = \sum_{\xi \in H^\perp} \widehat{f}(\xi)`
10
+ * in `\mathbb{Z}[\zeta_n]` (`subStride * dualStride == n`, `isPrimeNat subStride`),
11
+ * - Quadratic Gauss sum norm `G(\chi_p) \overline{G(\chi_p)} = p` in `\mathbb{Z}[\zeta_p]` (`p >= 3` odd prime),
12
+ * - Positive-semidefinite symmetric `2 × 2` Fock–Gram matrix `G` (`g01 == g10`, `g00 >= 0`, `g11 >= 0`,
13
+ * and Lagrange 4-squares `g00 * g11 - g01^2 = s_0^2 + s_1^2 + s_2^2 + s_3^2 >= 0`),
14
+ * - Rallis seesaw adjoint inner-product identity `<\Theta_K u, v> = <u, \Theta_{K^\dagger} v>`
15
+ * with verified transpose witness `K^\dagger = K^T`!
16
+ * 2. `ThetaAlg.StepanovCert p [a, b] mult [nLocus, nProj, ap, degP]`:
17
+ * - Smoothness of `C : y^2 = x^3 + a x + b / F_p` (`disc = (-4 a^3 - 27 b^2) mod p != 0`),
18
+ * - Explicit nonzero Stepanov auxiliary polynomial `P(x) \in F_p[x]` (`deg P = D`, `1 <= leadCoeff < p`),
19
+ * - Exact vanishing of Hasse–Schmidt derivatives `\mathcal{D}^{(0)} P(x_0) = ... = \mathcal{D}^{(mult-1)} P(x_0) = 0`
20
+ * at every Frobenius-rational `x`-coordinate `x_0 \in L(C, F_p)` via single-pass jet evaluation in
21
+ * `F_p[\varepsilon]/(\varepsilon^{mult})`,
22
+ * - Stepanov multiplicity bound `mult * nLocus + degSlack == D` and Weil 4-square bound `a_p^2 + \sum s_i^2 = 4 p`!
23
+ */
24
+ import { Term } from '../ast';
25
+ import { ElabEnv } from '../elab/env';
26
+ import { ProofState } from '../elab/tactics';
27
+ export type FourSquares = readonly [number, number, number, number];
28
+ export interface ThetaSeesawCertResult {
29
+ readonly p: number;
30
+ readonly n: number;
31
+ readonly subStride: number;
32
+ readonly dualStride: number;
33
+ readonly signal: readonly bigint[];
34
+ readonly gramFlat: readonly [bigint, bigint, bigint, bigint];
35
+ readonly seesawSpec: readonly [
36
+ bigint,
37
+ bigint,
38
+ bigint,
39
+ bigint,
40
+ bigint,
41
+ bigint,
42
+ bigint,
43
+ bigint
44
+ ];
45
+ readonly poissonCommonSum: bigint;
46
+ readonly gaussNormSq: bigint;
47
+ readonly gramDet: bigint;
48
+ readonly gramFourSquares: FourSquares;
49
+ readonly adjFlat: readonly [bigint, bigint, bigint, bigint];
50
+ readonly seesawCommonInner: bigint;
51
+ readonly summary: readonly [bigint, bigint, bigint, bigint];
52
+ }
53
+ export interface ForgedThetaSeesawOverrides {
54
+ readonly modSpec?: readonly number[];
55
+ readonly dualStride?: number;
56
+ readonly gramFlat?: readonly bigint[];
57
+ readonly gramFourSquares?: FourSquares;
58
+ readonly adjFlat?: readonly [bigint, bigint, bigint, bigint];
59
+ readonly summary?: readonly bigint[];
60
+ }
61
+ export interface StepanovCertResult {
62
+ readonly p: number;
63
+ readonly a: bigint;
64
+ readonly b: bigint;
65
+ readonly mult: number;
66
+ readonly discModP: number;
67
+ readonly discInv: number;
68
+ readonly qDisc: number;
69
+ readonly locusX: readonly number[];
70
+ readonly nLocus: number;
71
+ readonly nProj: number;
72
+ readonly ap: bigint;
73
+ readonly degP: number;
74
+ readonly degSlack: number;
75
+ readonly polyCoeffs: readonly number[];
76
+ readonly lagrangeSquares: FourSquares;
77
+ readonly summary: readonly [bigint, bigint, bigint, bigint];
78
+ }
79
+ export interface ForgedStepanovOverrides {
80
+ readonly p?: number;
81
+ readonly mult?: number;
82
+ readonly polyCoeffs?: readonly number[];
83
+ readonly degSlack?: number;
84
+ readonly summary?: readonly bigint[];
85
+ readonly lagrangeSquares?: FourSquares;
86
+ }
87
+ export declare function computeThetaSeesawCertData(modSpecInput: readonly number[], signalInput: readonly (number | bigint)[], gramInput: readonly (number | bigint)[], seesawInput: readonly (number | bigint)[]): ThetaSeesawCertResult;
88
+ /**
89
+ * Evaluates `P(x0 + \varepsilon)` in `F_p[\varepsilon]/(\varepsilon^{mult})`, returning
90
+ * `[D^(0)P(x0), D^(1)P(x0), ..., D^(mult-1)P(x0)] mod p` without dividing by `k!`.
91
+ */
92
+ export declare function evalHasseJetFp(polyCoeffs: readonly number[], x0: number, mult: number, p: number): readonly number[];
93
+ /**
94
+ * Constructs Stepanov's explicit nonzero auxiliary polynomial over `F_p` for smooth
95
+ * Weierstrass cubics `y^2 = f(x) = x^3 + a x + b` (`p >= 3` odd prime, `mult >= 2`).
96
+ *
97
+ * For `mult = 2`, builds Stepanov's canonical differential-Frobenius polynomial:
98
+ * `Q(x) = 2 f(x) (f(x)^{(p-1)/2} - 1) - f'(x) (x^p - x)`
99
+ * multiplied by `r_f(x) = \prod_{f(r)=0} (x - r)` (`deg P = #roots(f) + 3(p+1)/2`,
100
+ * leading coefficient `2 \not\equiv 0 (mod p)`!). For general `mult > 2`, raises the
101
+ * base Stepanov factor cleanly: `Q_mult = P_2(x)` when `mult = 2` and `P_2(x) * L_poly^{mult - 2}`
102
+ * so `mult >= 2` is genuinely supported for any higher multiplicity order!
103
+ */
104
+ export declare function computeStepanovCertData(p: number, cubicABInput: readonly (number | bigint)[], mult: number): StepanovCertResult;
105
+ export declare function mkThetaWitnessDataTupleType(): Term;
106
+ export declare function buildThetaSeesawCertWitnessTerm(solved: ThetaSeesawCertResult, overrides?: ForgedThetaSeesawOverrides): {
107
+ readonly certTypeTerm: Term;
108
+ readonly certProofTerm: Term;
109
+ };
110
+ export declare function mkStepanovWitnessDataTupleType(): Term;
111
+ export declare function buildStepanovCertWitnessTerm(solved: StepanovCertResult, overrides?: ForgedStepanovOverrides): {
112
+ readonly certTypeTerm: Term;
113
+ readonly certProofTerm: Term;
114
+ };
115
+ export declare function trySolveThetaSeesawGoal(state: ProofState): boolean;
116
+ export declare function trySolveStepanovGoal(state: ProofState): boolean;
117
+ export declare function installThetaStepanovTacticsOnly(env: ElabEnv): ElabEnv;
118
+ export declare function buildThetaF3Z4SeesawSpec(): {
119
+ readonly modSpec: readonly [number, number, number];
120
+ readonly signal: readonly bigint[];
121
+ readonly gramFlat: readonly [bigint, bigint, bigint, bigint];
122
+ readonly seesawSpec: readonly [
123
+ bigint,
124
+ bigint,
125
+ bigint,
126
+ bigint,
127
+ bigint,
128
+ bigint,
129
+ bigint,
130
+ bigint
131
+ ];
132
+ };
133
+ export declare function buildThetaF5Z6SeesawSpec(): {
134
+ readonly modSpec: readonly [number, number, number];
135
+ readonly signal: readonly bigint[];
136
+ readonly gramFlat: readonly [bigint, bigint, bigint, bigint];
137
+ readonly seesawSpec: readonly [
138
+ bigint,
139
+ bigint,
140
+ bigint,
141
+ bigint,
142
+ bigint,
143
+ bigint,
144
+ bigint,
145
+ bigint
146
+ ];
147
+ };
148
+ export declare function buildThetaF7Z7SeesawSpec(): {
149
+ readonly modSpec: readonly [number, number, number];
150
+ readonly signal: readonly bigint[];
151
+ readonly gramFlat: readonly [bigint, bigint, bigint, bigint];
152
+ readonly seesawSpec: readonly [
153
+ bigint,
154
+ bigint,
155
+ bigint,
156
+ bigint,
157
+ bigint,
158
+ bigint,
159
+ bigint,
160
+ bigint
161
+ ];
162
+ };
163
+ export declare function buildStepanovF3GaussSpec(): {
164
+ readonly p: number;
165
+ readonly cubicAB: readonly [bigint, bigint];
166
+ readonly mult: number;
167
+ };
168
+ export declare function buildStepanovF5OrdinarySpec(): {
169
+ readonly p: number;
170
+ readonly cubicAB: readonly [bigint, bigint];
171
+ readonly mult: number;
172
+ };
173
+ export declare function buildStepanovF7EisensteinSpec(): {
174
+ readonly p: number;
175
+ readonly cubicAB: readonly [bigint, bigint];
176
+ readonly mult: number;
177
+ };
178
+ export declare function buildStepanovF11CurveSpec(): {
179
+ readonly p: number;
180
+ readonly cubicAB: readonly [bigint, bigint];
181
+ readonly mult: number;
182
+ };
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Bidirectional Type, Universe, Mode & Duality Checker for `endash`.
3
+ *
4
+ * Enforces all six mathematical soundness invariants (`NC-1` through `NC-6`):
5
+ * - `NC-1`: `CatLax(u)` (`isStrict = false`) vs `CatCart(u)` (`isStrict = true`);
6
+ * `comp-prod-fun`, `hom-rep-fun`, diagonal Cartesian `fapp0`, and curried
7
+ * Cartesian `lam-fun` require `isStrict === true` (`Cart` mode).
8
+ * - `NC-2`: Exact `{ diff, tail }` duality checks; `dual-transf` checks
9
+ * `transfModeUnderDuality(mode, dual)` (rejecting `T` on lax transfors);
10
+ * `family-dual-fun` shifts the base by `familyBaseShift(dual)`.
11
+ * - `NC-3`: Functor conversion uses `mkFunVar` (`convFun`), never collapsing
12
+ * 1-object non-terminal categories to `TerminalCat`.
13
+ * - `NC-4`: 2-periodic `Sigma(+)` / `Sigma(-)` checks `fam : base -> CatCart`
14
+ * (for `+`) and `fam : Dual(T, base) -> CatCart` (for `-`).
15
+ * - `NC-5`: Bunched `;` vs `,` contexts track duality locks per stage; lax
16
+ * diagonal contraction and cross-stage exchange are rejected.
17
+ */
18
+ import { CatTerm, NaturalCellTerm, Term, VarSym } from './ast';
19
+ import { BunchedContext, GlobalEnv } from './context';
20
+ import { TransfMode } from './duality';
21
+ import { displayedBodyMentionsVar, naturalCellMentionsVar } from './eval';
22
+ import { VCat, VFun, VGrpd, Value } from './value';
23
+ export type EndashTypeErrorCode = 'EXPECTED_STRICT_CAT' | 'EXPECTED_CAT_UNIVERSE' | 'EXPECTED_GRPD' | 'EXPECTED_PI_GRPD' | 'EXPECTED_SIGMA_GRPD' | 'EXPECTED_FUNCTOR_TYPE' | 'EXPECTED_TRANSF_TYPE' | 'TYPE_MISMATCH' | 'CATEGORY_MISMATCH' | 'FUNCTOR_ENDPOINT_MISMATCH' | 'UNIVERSE_LEVEL_MISMATCH' | 'INVALID_TRANSF_DUALITY' | 'INVALID_FUNCTORIAL_BODY' | 'INVALID_NATURAL_CELL' | 'INVALID_DISPLAYED_BODY';
24
+ export declare class EndashTypeError extends Error {
25
+ readonly code: EndashTypeErrorCode;
26
+ constructor(code: EndashTypeErrorCode, message: string);
27
+ }
28
+ export interface CheckedCat {
29
+ readonly level: number;
30
+ readonly isStrict: boolean;
31
+ readonly val: VCat;
32
+ }
33
+ export interface CheckedGrpd {
34
+ readonly level: number;
35
+ readonly val: VGrpd;
36
+ }
37
+ export interface InferredTerm {
38
+ readonly ty: VGrpd;
39
+ readonly val: Value;
40
+ }
41
+ export declare function checkCat(ctx: BunchedContext, cat: CatTerm): CheckedCat;
42
+ export declare function checkGrpd(ctx: BunchedContext, term: Term): CheckedGrpd;
43
+ export declare function checkTerm(ctx: BunchedContext, term: Term, expectedTy: VGrpd): Value;
44
+ export declare function inferTerm(ctx: BunchedContext, term: Term): InferredTerm;
45
+ export declare function checkFunctorialObj(ctx: BunchedContext, term: Term, targetCat: VCat): Value;
46
+ export declare function checkNaturalCell(baseCtx: BunchedContext, mode: TransfMode, natSym: VarSym, domCat: VCat, codCat: VCat, srcFun: VFun, dstFun: VFun, cell: NaturalCellTerm): void;
47
+ /**
48
+ * Typecheck a closed transparent definition `name : typeTerm := bodyTerm` in `globals`
49
+ * and return the extended `GlobalEnv` caching its `VGrpd`, NbE `Value`, and transitive `axiomsUsed`.
50
+ */
51
+ export declare function declareDef(globals: GlobalEnv, name: string, typeTerm: Term, bodyTerm: Term): GlobalEnv;
52
+ /**
53
+ * Typecheck a closed theorem `name : typeTerm := proofTerm` in `globals`, seal its
54
+ * runtime NbE value as `{ tag: 'n-global-opaque', name, ty }` (`NC-7a`), and record
55
+ * its transitive `axiomsUsed` footprint (`NC-9a`).
56
+ */
57
+ export declare function declareTheorem(globals: GlobalEnv, name: string, typeTerm: Term, proofTerm: Term): GlobalEnv;
58
+ /**
59
+ * Typecheck a closed axiom `axiom name : typeTerm` in `globals`, seal its runtime NbE
60
+ * value as `{ tag: 'n-global-opaque', name, ty }`, and seed `axiomsUsed` with `name`
61
+ * (plus any axioms referenced in `typeTerm`) so `#print axioms` catches every transitive
62
+ * dependency in O(1) (`NC-9a`).
63
+ */
64
+ export declare function declareAxiom(globals: GlobalEnv, name: string, typeTerm: Term): GlobalEnv;
65
+ export { displayedBodyMentionsVar, naturalCellMentionsVar };
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Standalone Zero-Dependency `endash` CLI (`endash/src/cli/endash_cli.ts`).
4
+ *
5
+ * Subcommands:
6
+ * - `endash check <file-or-module> [--include <dir>] [--strict-axioms] [--json]`
7
+ * - `endash goals <file> <line>:<col> [--include <dir>] [--json]`
8
+ * - `endash axioms <file-or-module> [decl] [--include <dir>] [--json]`
9
+ * - `endash eval <file-or-module> "<expr>" [--include <dir>] [--json]`
10
+ * - `endash cas p1 <twist> [--field Q|F2] [--json]`
11
+ * - `endash cas snf "<json-matrix>" [--ring Z|Q|F2] [--json]`
12
+ * - `endash stdlib [--json]`
13
+ */
14
+ export interface CliIo {
15
+ readonly cwd?: string;
16
+ stdout(msg: string): void;
17
+ stderr(msg: string): void;
18
+ }
19
+ export declare function runEndashCli(argv: readonly string[], io?: Partial<CliIo>): number;
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Bunched Modal & Duality-Tracked Contexts for `endash`.
3
+ *
4
+ * A context `Γ` is an ordered list of stages separated by semicolons `;`:
5
+ * Γ = Stage_0 ; Stage_1 ; ... ; Stage_{m-1}
6
+ *
7
+ * Within each stage, variables form a symmetric Cartesian comma-bunch `,`.
8
+ *
9
+ * Key structural laws enforced by `BunchedContext`:
10
+ * 1. Object/groupoid variables (`mode = 'obj'`) may be referenced from any stage
11
+ * and under any category duality lock (since `Obj(Dual(σ, C)) ≡ Obj(C)`!).
12
+ * 2. Functorial variables (`mode = 'fun'`) track an active `Duality` lock `lock`
13
+ * (initialized to `DUAL_ID`). Applying `lockDuality(τ)` (e.g. entering the
14
+ * contravariant first slot of `Hom_A(-, +)` or `Dual(τ, -)`) composes `τ` onto
15
+ * functorial variables in the active scope. Using `x` requires `lock ≡ DUAL_ID`!
16
+ * Hence `λ^f x. Hom_A(x, x)` is immediately rejected (`x` needed at `T` and `Id`).
17
+ * 3. Semicolon boundaries `;` forbid unordered exchange across `;` and forbid
18
+ * lax diagonal contraction (using the same functorial variable across a
19
+ * non-`Cart` application).
20
+ */
21
+ import { VarSym } from './ast';
22
+ import { Duality } from './duality';
23
+ import { Env, VCat, VGrpd, Value } from './value';
24
+ export type BindingMode = 'obj' | 'fun' | 'nat';
25
+ export interface ContextEntry {
26
+ readonly sym: VarSym;
27
+ readonly mode: BindingMode;
28
+ readonly stageIndex: number;
29
+ /** Semantic `Grpd` type classifying `val` (`Obj(cat)` when `cat` is set). */
30
+ readonly type: VGrpd;
31
+ /** Semantic category when bound as `'fun'` or `'nat'` (or a category variable). */
32
+ readonly cat?: VCat;
33
+ /** Accumulated duality lock relative to the binding site (`DUAL_ID` means unflipped). */
34
+ readonly lock: Duality;
35
+ /** Semantic value assigned to this variable during NbE evaluation while typechecking. */
36
+ readonly evalValue: Value;
37
+ }
38
+ export declare class EndashModeError extends Error {
39
+ readonly code: 'UNBOUND_VARIABLE' | 'UNBOUND_GLOBAL' | 'DUPLICATE_GLOBAL_DECL' | 'DUALITY_LOCK_MISMATCH' | 'MODE_MISMATCH' | 'STAGE_EXCHANGE_FORBIDDEN' | 'LAX_DIAGONAL_FORBIDDEN';
40
+ constructor(code: 'UNBOUND_VARIABLE' | 'UNBOUND_GLOBAL' | 'DUPLICATE_GLOBAL_DECL' | 'DUALITY_LOCK_MISMATCH' | 'MODE_MISMATCH' | 'STAGE_EXCHANGE_FORBIDDEN' | 'LAX_DIAGONAL_FORBIDDEN', message: string);
41
+ }
42
+ export interface GlobalDeclEntry {
43
+ readonly name: string;
44
+ readonly kind: 'def' | 'theorem' | 'axiom';
45
+ readonly type: VGrpd;
46
+ readonly evalValue: Value;
47
+ /** Topological unfolding height (`1 + max_{g in refs(body)} height(g)` for `def`, `0` otherwise). */
48
+ readonly height: number;
49
+ /** Transitive set of `axiom` declaration names on which this declaration depends (`NC-9a`). */
50
+ readonly axiomsUsed: ReadonlySet<string>;
51
+ }
52
+ /**
53
+ * Immutable, strictly acyclic global declaration environment (`def` & opaque `theorem`).
54
+ * Every entry is checked in an earlier `GlobalEnv` snapshot before insertion, so
55
+ * cyclic or forward-referencing declarations are structurally impossible (`NC-7a`).
56
+ */
57
+ export declare class GlobalEnv {
58
+ private readonly decls_;
59
+ private readonly values_;
60
+ private constructor();
61
+ static empty(): GlobalEnv;
62
+ has(name: string): boolean;
63
+ get(name: string): GlobalDeclEntry | undefined;
64
+ valueMap(): ReadonlyMap<string, Value>;
65
+ lookup(name: string): GlobalDeclEntry;
66
+ extendChecked(entry: GlobalDeclEntry): GlobalEnv;
67
+ get size(): number;
68
+ entries(): IterableIterator<GlobalDeclEntry>;
69
+ }
70
+ export declare class BunchedContext {
71
+ private readonly entries_;
72
+ readonly stageCount: number;
73
+ readonly level: number;
74
+ readonly globals: GlobalEnv;
75
+ private constructor();
76
+ static empty(globals?: GlobalEnv): BunchedContext;
77
+ /** Extend the current comma-bunch `,` with an object/groupoid variable (`x :^obj T`). */
78
+ extendObj(sym: VarSym, type: VGrpd, evalValue: Value): BunchedContext;
79
+ /**
80
+ * Extend the current comma-bunch `,` (`newStage = false`) or start a new
81
+ * semicolon stage `;` (`newStage = true`) with a functorial variable `x :^f A`.
82
+ */
83
+ extendFun(sym: VarSym, cat: VCat, type: VGrpd, evalValue: Value, newStage?: boolean): BunchedContext;
84
+ /** Start a new ordered semicolon stage `;` with a natural variable `a :^n A`. */
85
+ extendNat(sym: VarSym, cat: VCat, type: VGrpd, evalValue: Value): BunchedContext;
86
+ /**
87
+ * Apply a category duality lock `sigma` to functorial variables:
88
+ * - Variables in the top stage receive `composeDuality(sigma, entry.lock)`;
89
+ * - Variables in earlier `;`-stages receive the right-shifted base duality
90
+ * `composeDuality(familyBaseShift^k(sigma), entry.lock)`!
91
+ */
92
+ lockDuality(sigma: Duality): BunchedContext;
93
+ /**
94
+ * Enter an object-only position (e.g. `Obj(C)` or an ordinary `Grpd` expression
95
+ * that forgets positive-dimensional cells): functorial variables remain usable as
96
+ * objects regardless of duality lock because `Obj(Dual(σ, A)) ≡ Obj(A)`, whereas
97
+ * raw `'nat'` variables may only appear in functorial endpoint expressions when
98
+ * explicitly projected as objects.
99
+ */
100
+ asObjectPosition(): BunchedContext;
101
+ lookup(sym: VarSym): ContextEntry;
102
+ /**
103
+ * Look up a variable in term position, enforcing functorial duality locks and
104
+ * preventing raw `'nat'` variables from escaping outside functorial/cell positions.
105
+ */
106
+ useVar(sym: VarSym, allowNatAsObj?: boolean): ContextEntry;
107
+ /** Extract the runtime NbE valuation `Env` (`O(1)` shared globals + local binders). */
108
+ toEnv(): Env;
109
+ entries(): IterableIterator<ContextEntry>;
110
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Exact eventually-constant bitstream duality algebra for omega-categories.
3
+ *
4
+ * Every element sigma in Z_2^* . {0^omega, 1^omega} specifies which positive
5
+ * dimensions d >= 1 reverse direction, using the canonical difference-from-tail
6
+ * representation:
7
+ *
8
+ * revDim(sigma, d) = sigma.tail XOR Boolean((sigma.diff >> (d - 1)) & 1)
9
+ *
10
+ * Because `diff` is a nonnegative BigInt whose top set bit (if any) automatically
11
+ * differs from `0`, EVERY `{ diff: bigint, tail: boolean }` with `diff >= 0n` is
12
+ * already in unique canonical normal form without any stripping pass!
13
+ */
14
+ export type TransfMode = 'cart' | 'lax' | 'oplax';
15
+ export interface Duality {
16
+ readonly diff: bigint;
17
+ readonly tail: boolean;
18
+ }
19
+ /** Identity duality: reverses no dimensions. */
20
+ export declare const DUAL_ID: Duality;
21
+ /** Total duality `O = TotalOp_cat`: reverses all dimensions d >= 1. */
22
+ export declare const DUAL_TOTAL_OP: Duality;
23
+ /** Dimension-1 duality `T = Op_cat`: reverses dimension 1 only. */
24
+ export declare const DUAL_OP: Duality;
25
+ /** Dimension-2 duality `C_2 = CoAt2_cat`: reverses dimension 2 only. */
26
+ export declare const DUAL_CO_AT_2: Duality;
27
+ /** Dimension-3 duality `C_3`: reverses dimension 3 only (`familyBaseShift(C_2)`). */
28
+ export declare const DUAL_CO_AT_3: Duality;
29
+ /** Above-1 duality `R = CoAbove2_cat`: keeps dim 1, reverses all dimensions d >= 2. */
30
+ export declare const DUAL_CO_ABOVE_2: Duality;
31
+ /** Single-dimension reversal `C_d` for d >= 1. */
32
+ export declare function dualAtDim(d: number): Duality;
33
+ /** Reverses all dimensions >= d, preserving dimensions < d. */
34
+ export declare function dualAboveOrEqualDim(d: number): Duality;
35
+ /** Exact syntactic/semantic equality (O(1)). */
36
+ export declare function dualityEqual(a: Duality, b: Duality): boolean;
37
+ export declare function isIdentityDuality(sigma: Duality): boolean;
38
+ /** Involutive group multiplication (bitwise XOR; every element has order <= 2). */
39
+ export declare function composeDuality(outer: Duality, inner: Duality): Duality;
40
+ /** Query whether dimension d >= 1 is reversed by `sigma`. */
41
+ export declare function revDim(sigma: Duality, d: number): boolean;
42
+ /**
43
+ * Left-shift when descending into `Hom_cat`:
44
+ * homShift(sigma)(d) = sigma(d + 1).
45
+ * Whether `Hom` swaps its two object endpoints is `revDim(sigma, 1)`.
46
+ */
47
+ export declare function homShift(sigma: Duality): Duality;
48
+ /**
49
+ * Right-shift induced on the base category `K` when applying fibrewise `sigma`
50
+ * to a `Cat_cart`-valued family `E : K -> Cat_cart`:
51
+ * familyBaseShift(sigma)(1) = false
52
+ * familyBaseShift(sigma)(d + 1) = sigma(d).
53
+ *
54
+ * Examples:
55
+ * familyBaseShift(T) = C_2
56
+ * familyBaseShift(C_2) = C_3
57
+ * familyBaseShift(O) = R (CoAbove2)
58
+ * homShift(familyBaseShift(sigma)) === sigma (exact left inverse!).
59
+ */
60
+ export declare function familyBaseShift(sigma: Duality): Duality;
61
+ /**
62
+ * Compute the transformed `TransfMode` when applying `sigma` to a transformation
63
+ * in `FunctorCat(mode, A, B)`, or `undefined` if `sigma` does not preserve the
64
+ * coherent omega-transformation profile.
65
+ *
66
+ * - For `'cart'` (`StrictTransfor`): ALL bitstreams `sigma` are valid because all
67
+ * higher laxity cells are identities.
68
+ * - For `'lax'` / `'oplax'`: valid iff `homShift(sigma)` is `ID` or `TOTAL_OP`
69
+ * (i.e. `sigma` is in `{ID, OP, CO_ABOVE_2, TOTAL_OP}`), transforming polarity
70
+ * by `pol' = pol XOR revDim(sigma, 1) XOR revDim(sigma, 2)`:
71
+ * - `ID` and `TOTAL_OP` preserve `'lax'` / `'oplax'`;
72
+ * - `OP` (`T`) and `CO_ABOVE_2` (`R`) swap `'lax' <-> 'oplax'`.
73
+ */
74
+ export declare function transfModeUnderDuality(mode: TransfMode, sigma: Duality): TransfMode | undefined;
75
+ /** Compact human-readable notation for diagnostics and pretty-printing. */
76
+ export declare function formatDuality(sigma: Duality): string;