@hotdocx/endash-kernel 0.0.0-stage → 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 +23 -0
  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 -0
  8. package/index.d.ts +20 -0
  9. package/index.mjs +704 -0
  10. package/node.cjs +116606 -0
  11. package/node.d.ts +8 -0
  12. package/node.mjs +53 -0
  13. package/package.json +69 -4
  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,117 @@
1
+ /**
2
+ * Phase F5 Browser-Safe Algebraic de Rham Cohomology, Cartier Characteristic-p Survival,
3
+ * & Singular Cusp Kähler Torsion CAS Solver + `by cas_derham` Tactic
4
+ * (`endash/src/cas/derham_hkr.ts`, `0` Node built-ins, `0` `src/stdlib/*` imports, `0` `any` casts).
5
+ *
6
+ * Certifies exact 3-term truncated algebraic de Rham cochain complexes
7
+ * `0 -> Ω^0 --d0--> Ω^1 --d1--> Ω^2 -> 0`
8
+ * over BOTH characteristic `0` (`charMod = 0`, exact rational `Q` via unimodular `Z`-SNF
9
+ * rank witnesses) and prime characteristic `p >= 2` (`charMod = p`, exact `GL(F_p)` Gauss–Jordan
10
+ * rank witnesses), verifying inside `src/check.ts` (`DeRhamAlg.DeRhamCert`):
11
+ * 1. Matrix dimensions `d0 : n1 x n0`, `d1 : n2 x n1`, and `betti = [h0, h1, h2]`;
12
+ * 2. Field characteristic validity (`charMod = 0` or `charMod >= 2` prime);
13
+ * 3. Exact cochain condition `d1 * d0 == 0` (over `Q` or `F_p`);
14
+ * 4. Exact invertible left/right change-of-basis matrices `(U_k, U_k^{-1}, V_k, V_k^{-1})`
15
+ * diagonalizing `U_k * d_k * V_k` to rank `r_k` (`k = 0, 1`);
16
+ * 5. Cohomology rank equations `h0 + r0 = n0`, `h1 + r0 + r1 = n1`, `h2 + r1 = n2`!
17
+ */
18
+ import { Term } from '../ast';
19
+ import { ElabEnv } from '../elab/env';
20
+ export type IntMatrix2D = readonly (readonly bigint[])[];
21
+ export interface DeRhamRankWitness {
22
+ readonly rank: number;
23
+ readonly U: IntMatrix2D;
24
+ readonly UInv: IntMatrix2D;
25
+ readonly V: IntMatrix2D;
26
+ readonly VInv: IntMatrix2D;
27
+ }
28
+ export interface DeRhamCertResult {
29
+ readonly charMod: number;
30
+ readonly n0: number;
31
+ readonly n1: number;
32
+ readonly n2: number;
33
+ readonly d0: IntMatrix2D;
34
+ readonly d1: IntMatrix2D;
35
+ readonly rk0: DeRhamRankWitness;
36
+ readonly rk1: DeRhamRankWitness;
37
+ readonly betti: readonly [number, number, number];
38
+ }
39
+ export interface ForgedDeRhamOverrides {
40
+ readonly charMod?: number;
41
+ readonly n0?: number;
42
+ readonly n1?: number;
43
+ readonly n2?: number;
44
+ readonly d0?: IntMatrix2D;
45
+ readonly d1?: IntMatrix2D;
46
+ readonly betti?: readonly number[];
47
+ readonly rk0?: Partial<DeRhamRankWitness>;
48
+ readonly rk1?: Partial<DeRhamRankWitness>;
49
+ }
50
+ export declare function computeDeRhamCertData(charMod: number, n0: number, n1: number, n2: number, d0: IntMatrix2D, d1: IntMatrix2D): DeRhamCertResult;
51
+ export declare function reifySignedBigIntTerm(z: bigint): Term;
52
+ export declare function reifyIntMat2DTerm(mat: IntMatrix2D): Term;
53
+ export declare function reifyNatArrayTerm(xs: readonly number[]): Term;
54
+ export declare function mkDeRhamWitnessDataTupleType(): Term;
55
+ export declare function buildDeRhamCertWitnessTerm(solved: DeRhamCertResult, overrides?: ForgedDeRhamOverrides): {
56
+ readonly certTypeTerm: Term;
57
+ readonly certProofTerm: Term;
58
+ };
59
+ /**
60
+ * 1. Polynomial Plane `A^2_Q = Spec Q[x, y]` truncated at total degree `<= 2`:
61
+ * - `Ω^0_{<=2}` basis `{1, x, y, x^2, xy, y^2}` (`n0 = 6`)
62
+ * - `Ω^1_{<=1}` basis `{dx, x dx, y dx, dy, x dy, y dy}` (`n1 = 6`)
63
+ * - `Ω^2_{<=0}` basis `{dx ∧ dy}` (`n2 = 1`)
64
+ * Certifies algebraic Poincaré vanishing `betti = [1, 0, 0]`!
65
+ */
66
+ export declare function buildAffinePlaneA2RatDeRhamSpec(): {
67
+ readonly charMod: number;
68
+ readonly n0: number;
69
+ readonly n1: number;
70
+ readonly n2: number;
71
+ readonly d0: IntMatrix2D;
72
+ readonly d1: IntMatrix2D;
73
+ };
74
+ /**
75
+ * 2. Punctured Multiplicative Group `G_{m,Q} = Spec Q[t, t^{-1}]` on Laurent window `t^{-2}..t^2`:
76
+ * - `Ω^0` basis `{t^{-2}, t^{-1}, 1, t, t^2}` (`n0 = 5`)
77
+ * - `Ω^1` basis `{t^{-3} dt, t^{-2} dt, t^{-1} dt, dt, t dt}` (`n1 = 5`)
78
+ * - `Ω^2 = 0` (`n2 = 0`)
79
+ * Certifies `[1, 1, 0]`: `H^0_{dR} ≅ Q·1` and `H^1_{dR}(G_{m,Q}) ≅ Q·[dt / t] ≠ 0`!
80
+ */
81
+ export declare function buildPuncturedGmRatDeRhamSpec(): {
82
+ readonly charMod: number;
83
+ readonly n0: number;
84
+ readonly n1: number;
85
+ readonly n2: number;
86
+ readonly d0: IntMatrix2D;
87
+ readonly d1: IntMatrix2D;
88
+ };
89
+ /**
90
+ * 3. Characteristic-2 Cartier Cohomology Survival on `F_2[x]_{<4}` (`charMod = 2`, `Stacks 0FKL` / `SGA 7`):
91
+ * - `Ω^0` basis `{1, x, x^2, x^3}` (`n0 = 4`)
92
+ * - `Ω^1` basis `{dx, x dx, x^2 dx}` (`n1 = 3`)
93
+ * - `Ω^2 = 0` (`n2 = 0`)
94
+ * Since `d(x^2) = 2x dx ≡ 0 (mod 2)`, `ker(d0) = span{1, x^2}` (`h0 = 2`) and `[x dx] ∉ im(d0)` (`h1 = 1`)!
95
+ */
96
+ export declare function buildChar2CartierF2xDeRhamSpec(): {
97
+ readonly charMod: number;
98
+ readonly n0: number;
99
+ readonly n1: number;
100
+ readonly n2: number;
101
+ readonly d0: IntMatrix2D;
102
+ readonly d1: IntMatrix2D;
103
+ };
104
+ /**
105
+ * 4. Singular Cusp Curve `C = Spec Q[x, y]/(y^2 - x^3)` in weighted degree `5` (`wt(x)=2, wt(y)=3`):
106
+ * - Curve Kähler 1-form complex `0 -> B_5 -> Ω^1_{B/Q, 5} -> 0` (`n0 = 1`: `{xy}`, `n1 = 2`: `{y dx, x dy}`, `n2 = 0`):
107
+ * `d0(xy) = y dx + x dy`, leaving the singular Kähler torsion 1-form `[y dx - x dy] ≠ 0` (`betti = [0, 1, 0]`)!
108
+ */
109
+ export declare function buildSingularCuspKahlerJumpRatSpec(): {
110
+ readonly charMod: number;
111
+ readonly n0: number;
112
+ readonly n1: number;
113
+ readonly n2: number;
114
+ readonly d0: IntMatrix2D;
115
+ readonly d1: IntMatrix2D;
116
+ };
117
+ export declare function installDeRhamTacticsOnly(env: ElabEnv): ElabEnv;
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Phase B5 Multiplicative Graded `Ext` Yoneda-Product Algebra CAS & LCF Proof Bridge
3
+ * (`endash/src/cas/ext_algebra.ts`).
4
+ *
5
+ * Implements constructive chain-map lifting of cocycles across projective resolutions
6
+ * (Lurie *Higher Algebra* §1.1.2.15 & §1.3.2 / Kerodon `017P` / Weibel §2.7) together
7
+ * with an air-tight `0`-axiom LCF kernel certificate (`ExtAlg.YonedaNonzeroCert` &
8
+ * `ExtAlg.YonedaZeroCert`) and `.en` tactic **`cas_ext_mul`**:
9
+ * 1. Solves the exact chain-map lifting equation `d_1 * alpha_1 = alpha_0 * d_2`
10
+ * over both the dual numbers `R = F_2[x]/(x^2)` (`modX2 = true`) and the bivariate
11
+ * Koszul polynomial ring `R = F_2[x, y]` (`modX2 = false`);
12
+ * 2. Evaluates the Yoneda cup product cocycle `gamma = aug(beta_0 * alpha_1)` in
13
+ * `Hom_R(P_2, F_2)`;
14
+ * 3. Certifies either non-vanishing `[gamma] != 0 in Ext^2_R(F_2, F_2)` via a
15
+ * separating hyperplane column `w` (`aug(d_2) * w = 0` and `gamma * w = [[true]]`)
16
+ * or vanishing `[gamma] = 0` via an explicit coboundary `u` (`u * aug(d_2) = gamma`);
17
+ * 4. Deterministically rejects forged non-chain-map lifts (`d_1 * alpha_1 != alpha_0 * d_2`)
18
+ * and forged Yoneda-product classes (`NC-14b` Part 2).
19
+ *
20
+ * **`0 LOC` TCB delta**; **`0` axioms**; **`0` Node built-ins** (browser-safe!).
21
+ */
22
+ import { Term } from '../ast';
23
+ import { GlobalEnv } from '../context';
24
+ import { ElabEnv } from '../elab/env';
25
+ import { DenseMatrix } from './matrix';
26
+ /**
27
+ * Normalized polynomial `sum_{i >= 0} c_i(y) * x^i` in `F_2[x, y]` where each
28
+ * `c_i(y)` is a normalized `boolean[]` (`sum_{j >= 0} c_{i,j} * y^j`) with no trailing `false`s,
29
+ * and `Poly2Val` has no trailing empty `[]` coefficients.
30
+ */
31
+ export type Poly2Val = readonly (readonly boolean[])[];
32
+ export declare function normPoly2(rows: readonly (readonly boolean[])[]): Poly2Val;
33
+ export declare const POLY2_ZERO: Poly2Val;
34
+ export declare const POLY2_ONE: Poly2Val;
35
+ export declare const POLY2_X: Poly2Val;
36
+ export declare const POLY2_Y: Poly2Val;
37
+ export declare function poly2Add(p: Poly2Val, q: Poly2Val): Poly2Val;
38
+ export declare function poly2Mul(modX2: boolean, p: Poly2Val, q: Poly2Val): Poly2Val;
39
+ export declare function poly2Eq(p: Poly2Val, q: Poly2Val): boolean;
40
+ export declare function poly2Aug(p: Poly2Val): boolean;
41
+ export interface Poly2Matrix {
42
+ readonly rows: number;
43
+ readonly cols: number;
44
+ readonly entries: readonly (readonly Poly2Val[])[];
45
+ }
46
+ export declare function mkPoly2Matrix(rows: number, cols: number, entries: readonly (readonly Poly2Val[])[]): Poly2Matrix;
47
+ export declare function poly2MatMul(modX2: boolean, A: Poly2Matrix, B: Poly2Matrix): Poly2Matrix;
48
+ export declare function poly2MatEq(A: Poly2Matrix, B: Poly2Matrix): boolean;
49
+ export declare function poly2MatIsZero(A: Poly2Matrix): boolean;
50
+ export declare function poly2AugMatrix(A: Poly2Matrix): DenseMatrix<bigint>;
51
+ export interface YonedaCupInput {
52
+ readonly modX2: boolean;
53
+ readonly r0: number;
54
+ readonly r1: number;
55
+ readonly r2: number;
56
+ readonly d1: Poly2Matrix;
57
+ readonly d2: Poly2Matrix;
58
+ /** Lifted 1-cocycle `alpha_0 : P_1 -> P_0` (`1 x r1` with `r0 = 1`). */
59
+ readonly alpha0: Poly2Matrix;
60
+ /** Lifted 1-cocycle `beta_0 : P_1 -> P_0` (`1 x r1` with `r0 = 1`). */
61
+ readonly beta0: Poly2Matrix;
62
+ }
63
+ export interface YonedaCupResult {
64
+ readonly input: YonedaCupInput;
65
+ /** Lifted chain map component `alpha_1 : P_2 -> P_1` (`r1 x r2`) with `d_1 * alpha_1 = alpha_0 * d_2`. */
66
+ readonly alpha1: Poly2Matrix;
67
+ /** Yoneda cup cocycle `gamma = aug(beta_0 * alpha_1) : P_2 -> F_2` (`1 x r2`). */
68
+ readonly gamma: DenseMatrix<bigint>;
69
+ readonly isNonzeroClass: boolean;
70
+ /** Present when `isNonzeroClass === true`: `aug(d_2) * w = 0` & `gamma * w = [[1n]]`. */
71
+ readonly separatingColW?: DenseMatrix<bigint>;
72
+ /** Present when `isNonzeroClass === false`: `u * aug(d_2) = gamma`. */
73
+ readonly coboundaryRowU?: DenseMatrix<bigint>;
74
+ }
75
+ /**
76
+ * Solve `d_1 * alpha_1 = rhs` (`r0 x r1` times `r1 x r2` = `r0 x r2`) over `F_2[x, y]`
77
+ * or `F_2[x]/(x^2)` by bounded monomial-basis expansion over `F_2` (`solveLinearSystem`).
78
+ */
79
+ export declare function solvePoly2ChainLift(modX2: boolean, d1: Poly2Matrix, rhs: Poly2Matrix, maxDeg?: number): Poly2Matrix | null;
80
+ /**
81
+ * Full constructive Yoneda cup product solver (`[beta] ⌣ [alpha] in Ext^2_R(F_2, F_2)`).
82
+ */
83
+ export declare function computeYonedaCupProduct2(input: YonedaCupInput): YonedaCupResult;
84
+ /** Benchmark 1: Dual numbers `R = F_2[x]/(x^2)`, generator `v in Ext^1`, `v ⌣ v != 0 in Ext^2`! */
85
+ export declare function buildF2DualNumbersYonedaInput(): YonedaCupInput;
86
+ /** Benchmark 2: Koszul `R = F_2[x, y]`, generators `e_1 = [1, 0]` and `e_2 = [0, 1]` in `Ext^1`! */
87
+ export declare function buildKoszulF2xyYonedaInput(whichBeta: 1 | 2, whichAlpha: 1 | 2): YonedaCupInput;
88
+ export declare function reifyPoly2Term(p: Poly2Val): Term;
89
+ export declare function reifyPoly2MatrixTerm(M: Poly2Matrix): Term;
90
+ export declare function installExtAlgebraDefsWithCallback(defFn: (fullName: string, ty: Term, body: Term) => void): void;
91
+ export declare function getExtAlgebraKernelGlobalEnv(): GlobalEnv;
92
+ export declare function buildYonedaCupCertWitnessTerm(res: YonedaCupResult): {
93
+ readonly certTypeTerm: Term;
94
+ readonly certProofTerm: Term;
95
+ };
96
+ /**
97
+ * Certify a Yoneda cup-product step in the trusted `endash` kernel (`declareTheorem` -> `checkTerm`,
98
+ * `0` axioms!), supporting `forgedOverrides` so `NC-14b` Part 2 verifies deterministic kernel rejection
99
+ * of forged non-chain-map cocycle lifts (`d_1 * alpha_1 != alpha_0 * d_2`) and forged cohort classes!
100
+ */
101
+ export declare function certifyYonedaCupInKernel(input: YonedaCupInput, forgedOverrides?: {
102
+ readonly alpha1?: Poly2Matrix;
103
+ readonly gamma?: DenseMatrix<bigint>;
104
+ readonly separatingColW?: DenseMatrix<bigint>;
105
+ readonly coboundaryRowU?: DenseMatrix<bigint>;
106
+ readonly forceNonzeroClass?: boolean;
107
+ }): {
108
+ readonly solved: YonedaCupResult;
109
+ readonly certTypeTerm: Term;
110
+ readonly certProofTerm: Term;
111
+ };
112
+ export declare function installExtAlgebraTacticOnly(env: ElabEnv): ElabEnv;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Phase H3 Typed CAS (Part 5): Certificate-Producing Buchberger Gröbner Bases,
3
+ * Ideal Membership Cofactors, & Schreyer Syzygy Modules (`endash/src/cas/groebner_syzygy.ts`).
4
+ *
5
+ * Every basis element carries an explicit polynomial transformation row over the
6
+ * input generators (`G = liftMatrix * F` and `F = backMatrix * G`), and every
7
+ * syzygy column is verified to annihilate `F` (`row(F) * syzBasis = 0`)!
8
+ */
9
+ import { DenseMatrix } from './matrix';
10
+ import { MultiPoly, MultivariatePolyRing } from './poly';
11
+ import { ExactField } from './rings';
12
+ export interface GroebnerCertificate<C> {
13
+ readonly basis: readonly MultiPoly<C>[];
14
+ /** `s x m` matrix over `ring` such that `col(basis) = liftMatrix * col(generators)`. */
15
+ readonly liftMatrix: DenseMatrix<MultiPoly<C>>;
16
+ /** `m x s` matrix over `ring` such that `col(generators) = backMatrix * col(basis)`. */
17
+ readonly backMatrix: DenseMatrix<MultiPoly<C>>;
18
+ }
19
+ export interface IdealMembershipCertificate<C> {
20
+ readonly inIdeal: boolean;
21
+ readonly remainder: MultiPoly<C>;
22
+ /** Length-`m` cofactors `[c_0, ..., c_{m-1}]` with `h = sum_j c_j * generators[j]` when `inIdeal`. */
23
+ readonly cofactors: readonly MultiPoly<C>[] | null;
24
+ }
25
+ export interface SyzygyCertificate<C> {
26
+ /** `m x k` matrix over `ring` whose columns generate `Syz(generators)` (`row(F) * basis = 0`). */
27
+ readonly basis: DenseMatrix<MultiPoly<C>>;
28
+ readonly groebner: GroebnerCertificate<C>;
29
+ }
30
+ /**
31
+ * Compute a monic reduced Gröbner basis of `generators` over `ring` (with field coefficients),
32
+ * tracking exact transformation matrices `liftMatrix` (`G = L * F`) and `backMatrix` (`F = B * G`).
33
+ */
34
+ export declare function groebnerBasis<C>(field: ExactField<C>, ring: MultivariatePolyRing<C>, generators: readonly MultiPoly<C>[]): GroebnerCertificate<C>;
35
+ /**
36
+ * Decide ideal membership `h in <generators>` and produce exact cofactors `c_j` over
37
+ * the ORIGINAL `generators` when `inIdeal === true`.
38
+ */
39
+ export declare function idealMember<C>(field: ExactField<C>, ring: MultivariatePolyRing<C>, generators: readonly MultiPoly<C>[], gb: GroebnerCertificate<C>, h: MultiPoly<C>): IdealMembershipCertificate<C>;
40
+ /**
41
+ * Schreyer's theorem: compute a complete generating matrix (`m x k`) for `Syz(generators)`.
42
+ */
43
+ export declare function syzygyModule<C>(field: ExactField<C>, ring: MultivariatePolyRing<C>, generators: readonly MultiPoly<C>[]): SyzygyCertificate<C>;
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Phase A5 Browser-Safe Projective Gröbner & Hilbert–Serre CAS Solver + `by cas_hilbert` Tactic
3
+ * (`endash/src/cas/hilbert_proj_ag.ts`, `0` Node built-ins, `0` `src/stdlib/*` imports, `0` `any` casts).
4
+ *
5
+ * Computes exact reduced `degrevlex` Gröbner bases over `Q[x_0, ..., x_{n-1}]`, clears rational
6
+ * denominators to exact `BigInt` certificates (`D_L * G = L_Z * F`, `D_B * F = B_Z * G`, and
7
+ * Buchberger S-polynomial standard representations `D_S * S_Z(g_i, g_j) = sum_k q_k * g_k` with
8
+ * strict `degrevlex` quotient bounds), computes exact graded Hilbert functions `HF_{S/I}(d)` and
9
+ * exact **Hilbert–Serre binomial polynomials** `HP_{S/I}(d) = sum_{k=0}^{dim X} c_k * C(d, k)`,
10
+ * and constructs packed zero-redex LCF witness terms verified by `GradedAlg.HilbertCert`!
11
+ */
12
+ import { Term } from '../ast';
13
+ import { ElabEnv } from '../elab/env';
14
+ import { Monomial } from './poly';
15
+ export interface IntPolyTerm {
16
+ readonly coeff: bigint;
17
+ readonly exp: readonly number[];
18
+ }
19
+ export type IntSparsePoly = readonly IntPolyTerm[];
20
+ export interface IntSPairWitness {
21
+ readonly denomS: number;
22
+ readonly quotients: readonly IntSparsePoly[];
23
+ }
24
+ export interface ProjectiveHilbertResult {
25
+ readonly nVars: number;
26
+ /** Canonical descending `degrevlex` homogeneous input generators. */
27
+ readonly canonGens: readonly IntSparsePoly[];
28
+ /** Primitive positive-LC reduced `degrevlex` Gröbner basis over `Z[x_0, ..., x_{n-1}]`. */
29
+ readonly gbBasis: readonly IntSparsePoly[];
30
+ readonly denomL: number;
31
+ readonly liftMat: readonly (readonly IntSparsePoly[])[];
32
+ readonly denomB: number;
33
+ readonly backMat: readonly (readonly IntSparsePoly[])[];
34
+ /** Triangular S-pair witness rows (`sPairRows[i]` has length `|G| - 1 - i` for `j = i+1 .. |G|-1`, plus `[]` at `s - 1`? Wait: exact length `|G|`, where `sPairRows[i]` pairs `g_i` with `g_{i+1..s-1}`). */
35
+ readonly sPairRows: readonly (readonly IntSPairWitness[])[];
36
+ readonly leadingMonomials: readonly Monomial[];
37
+ readonly hfValues: readonly number[];
38
+ /** Exact integer binomial-basis coefficients `[c_0, ..., c_{projDim}]` of `HP_{S/I}(d) = ∑ c_k C(d, k)`. */
39
+ readonly hpBinomCoeffs: readonly bigint[];
40
+ readonly projDim: number;
41
+ readonly projDeg: number;
42
+ readonly arithGenus: bigint;
43
+ }
44
+ export interface ForgedHilbertOverrides {
45
+ readonly gens?: readonly IntSparsePoly[];
46
+ readonly gbBasis?: readonly IntSparsePoly[];
47
+ readonly denomL?: number;
48
+ readonly liftMat?: readonly (readonly IntSparsePoly[])[];
49
+ readonly denomB?: number;
50
+ readonly backMat?: readonly (readonly IntSparsePoly[])[];
51
+ readonly sPairRows?: readonly (readonly IntSPairWitness[])[];
52
+ readonly hfValues?: readonly number[];
53
+ readonly hpBinomCoeffs?: readonly bigint[];
54
+ readonly projDim?: number;
55
+ readonly projDeg?: number;
56
+ readonly arithGenus?: bigint;
57
+ }
58
+ export declare function evalExactHilbertFnByIncExc(nVars: number, lms: readonly Monomial[], d: number): number;
59
+ export declare function computeProjectiveHilbertCertData(nVars: number, rawGens: readonly IntSparsePoly[], hfPrefixLen?: number): ProjectiveHilbertResult;
60
+ export declare function reifySignedIntTerm(z: bigint): Term;
61
+ export declare function reifyNatListTerm(xs: readonly number[]): Term;
62
+ export declare function reifyIntListTerm(xs: readonly bigint[]): Term;
63
+ export declare function reifyIntSparsePolyTerm(p: IntSparsePoly): Term;
64
+ export declare function reifyIntSparsePolyListTerm(ps: readonly IntSparsePoly[]): Term;
65
+ export declare function reifyIntSparsePolyMatTerm(mat: readonly (readonly IntSparsePoly[])[]): Term;
66
+ export declare function reifySPairRowsTerm(rows: readonly (readonly IntSPairWitness[])[]): Term;
67
+ export declare function mkHilbertWitnessDataTupleType(): Term;
68
+ export declare function packHilbertWitnessTupleTerm(gbBasisT: Term, denomLT: Term, liftMatT: Term, denomBT: Term, backMatT: Term, sPairRowsT: Term): Term;
69
+ export declare function buildHilbertCertWitnessTerm(solved: ProjectiveHilbertResult, overrides?: ForgedHilbertOverrides): {
70
+ readonly certTypeTerm: Term;
71
+ readonly certProofTerm: Term;
72
+ };
73
+ export declare function buildProjPlaneP2Gens(): {
74
+ readonly nVars: number;
75
+ readonly gens: readonly IntSparsePoly[];
76
+ };
77
+ export declare function buildSmoothConicP2Gens(): {
78
+ readonly nVars: number;
79
+ readonly gens: readonly IntSparsePoly[];
80
+ };
81
+ export declare function buildEllipticCubicP2Gens(): {
82
+ readonly nVars: number;
83
+ readonly gens: readonly IntSparsePoly[];
84
+ };
85
+ export declare function buildTwistedCubicP3Gens(): {
86
+ readonly nVars: number;
87
+ readonly gens: readonly IntSparsePoly[];
88
+ };
89
+ export declare function buildBezoutConicLineP2Gens(): {
90
+ readonly nVars: number;
91
+ readonly gens: readonly IntSparsePoly[];
92
+ };
93
+ export declare function buildBlowupA2ReesGens(): {
94
+ readonly nVars: number;
95
+ readonly gens: readonly IntSparsePoly[];
96
+ };
97
+ export declare function installHilbertAgTacticsOnly(env: ElabEnv): ElabEnv;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Phase H3 Typed CAS (Part 4): Certificate-Producing Hermite Normal Form (HNF),
3
+ * Smith Normal Form (SNF), Linear System Solver, & Free-Module Kernel Basis
4
+ * over ANY `EuclideanDomain<T>` (`Z`, `Q`, `F_p`, `Q[x]`, `F_p[x]`)
5
+ * (`endash/src/cas/hnf_snf.ts`).
6
+ *
7
+ * Every normal-form routine maintains BOTH unimodular transformation matrices
8
+ * AND their exact unimodular inverses (`U * UInv = I`, `V * VInv = I`) via
9
+ * closed-form 2x2 Bézout steps, and self-verifies all certificates before returning!
10
+ */
11
+ import { DenseMatrix } from './matrix';
12
+ import { EuclideanDomain } from './rings';
13
+ export interface HnfCertificate<T> {
14
+ readonly U: DenseMatrix<T>;
15
+ readonly UInv: DenseMatrix<T>;
16
+ readonly H: DenseMatrix<T>;
17
+ readonly pivotCols: readonly number[];
18
+ readonly rank: number;
19
+ }
20
+ export interface SnfCertificate<T> {
21
+ readonly U: DenseMatrix<T>;
22
+ readonly UInv: DenseMatrix<T>;
23
+ readonly D: DenseMatrix<T>;
24
+ readonly V: DenseMatrix<T>;
25
+ readonly VInv: DenseMatrix<T>;
26
+ readonly invariantFactors: readonly T[];
27
+ /** Witness `divWitnesses[i]` such that `invariantFactors[i + 1] = divWitnesses[i] * invariantFactors[i]`. */
28
+ readonly divWitnesses: readonly T[];
29
+ readonly rank: number;
30
+ }
31
+ export interface FreeKernelCertificate<T> {
32
+ /** Basis columns `K` (`n x nullity`) such that `M * K = 0`. */
33
+ readonly basis: DenseMatrix<T>;
34
+ /** Retraction `KPlus` (`nullity x n`) such that `KPlus * K = I_nullity`. */
35
+ readonly retraction: DenseMatrix<T>;
36
+ readonly nullity: number;
37
+ }
38
+ export declare function hermiteNormalForm<T>(domain: EuclideanDomain<T>, M: DenseMatrix<T>): HnfCertificate<T>;
39
+ export declare function smithNormalForm<T>(domain: EuclideanDomain<T>, M: DenseMatrix<T>): SnfCertificate<T>;
40
+ /**
41
+ * Exact free basis `K` (`n x (n - rank)`) of `ker(M)` over any Euclidean integral domain,
42
+ * together with split left-inverse `retraction * basis = I`!
43
+ */
44
+ export declare function kernelFromSnf<T>(M: DenseMatrix<T>, snf: SnfCertificate<T>): FreeKernelCertificate<T>;
45
+ /**
46
+ * Exact matrix linear solver: finds `X` (`n x k`) with `A * X = B`, or returns `null` if
47
+ * no solution exists over `domain`.
48
+ */
49
+ export declare function solveLinearSystem<T>(domain: EuclideanDomain<T>, A: DenseMatrix<T>, B: DenseMatrix<T>): DenseMatrix<T> | null;
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Phase W5 Browser-Safe Grothendieck–Lefschetz Frobenius Trace, Elliptic Zeta
3
+ * Polynomials `P_1(t) = 1 - a_p t + p t^2`, & Lagrange 4-Square Hasse–Weil Certifier
4
+ * (`endash/src/cas/lefschetz_weil.ts`, `0` Node built-ins, `0` `src/stdlib/*` imports, `0` `any` casts).
5
+ *
6
+ * Certifies general projective Weierstrass cubics `E / F_p`:
7
+ * `Y^2 Z + a_1 X Y Z + a_3 Y Z^2 = X^3 + a_2 X^2 Z + a_4 X Z^2 + a_6 Z^3`
8
+ * (`coeffs = [a1, a2, a3, a4, a6]`, valid in ALL characteristics `p >= 2`, including `p = 2` and `p = 3`!),
9
+ * verifying inside `src/check.ts` (`WeilAlg.WeilTraceCert p coeffs [N1, N2, ap]`):
10
+ * 1. `p` is prime (`p >= 2`), `len(coeffs) == 5`, and `len(summary) == 3`;
11
+ * 2. **Geometric Smoothness over `F_p^{alg}`**: Tate's universal Weierstrass discriminant
12
+ * `Δ(a_1, a_2, a_3, a_4, a_6)` satisfies `disc * discInv == 1 + p * qDisc` (rejecting
13
+ * singular nodal and cuspidal cubics!);
14
+ * 3. **Genuine Quadratic Field Extension `F_{p^2} = F_p[α]/(α^2 + c_1 α + c_0)`**:
15
+ * `z^2 + c_1 z + c_0 == r_z + p * q_z` with `1 <= r_z < p` for all `z ∈ 0..p-1`;
16
+ * 4. **Exact Base & Quadratic Point Counts (`0` Neutral `natMod` Quotient Witnesses)**:
17
+ * `N_1 = |E(F_p)|` and `N_2 = |E(F_{p^2})|` (direct constant-field enumeration for `p = 2`,
18
+ * and `O(p^2)` division-free quotient-witness Euler/Vieta fiber certificates for odd `p >= 3`
19
+ * with `η^{(p^2 - 1)/2} = (p - 1, 0)`);
20
+ * 5. **Grothendieck–Lefschetz Trace & Quadratic Newton Recurrence**:
21
+ * `a_p + N_1 == p + 1` and `N_2 + |a_p|^2 == (p + 1)^2`;
22
+ * 6. **Deligne / Hasse–Weil Riemann Hypothesis (`|a_p| <= 2√p`)**:
23
+ * Lagrange four-square identity `|a_p|^2 + s_0^2 + s_1^2 + s_2^2 + s_3^2 == 4 p`!
24
+ */
25
+ import { Term } from '../ast';
26
+ import { ElabEnv } from '../elab/env';
27
+ import { ProofState } from '../elab/tactics';
28
+ export type WeierstrassCoeffs = readonly [bigint, bigint, bigint, bigint, bigint];
29
+ export type NatPair = readonly [number, number];
30
+ export interface Fp2PowStepWitness {
31
+ readonly bit: boolean;
32
+ readonly nextAcc: NatPair;
33
+ readonly qAcc: NatPair;
34
+ readonly nextCur: NatPair;
35
+ readonly qCur: NatPair;
36
+ }
37
+ export interface Fp2FiberQuotWitness {
38
+ readonly x2: NatPair;
39
+ readonly qX2: NatPair;
40
+ readonly dx: NatPair;
41
+ readonly qDx: NatPair;
42
+ readonly isSquare: boolean;
43
+ readonly u: NatPair;
44
+ readonly uSq: NatPair;
45
+ readonly qUSq: NatPair;
46
+ readonly qEtaUSq: NatPair;
47
+ }
48
+ export interface WeilCertResult {
49
+ readonly p: number;
50
+ readonly coeffs: WeierstrassCoeffs;
51
+ readonly N1: number;
52
+ readonly N2: number;
53
+ readonly ap: bigint;
54
+ readonly discModP: number;
55
+ readonly discInv: number;
56
+ readonly qDisc: number;
57
+ readonly c1: number;
58
+ readonly negC1: number;
59
+ readonly c0: number;
60
+ readonly negC0: number;
61
+ readonly quadNonRootWits: readonly NatPair[];
62
+ readonly eta: NatPair;
63
+ readonly powSteps: readonly Fp2PowStepWitness[];
64
+ readonly fp2FiberWitnesses: readonly Fp2FiberQuotWitness[];
65
+ readonly lagrangeSquares: readonly [number, number, number, number];
66
+ /** `[N1, N2, ap]` */
67
+ readonly summary: readonly [bigint, bigint, bigint];
68
+ }
69
+ export interface ForgedWeilOverrides {
70
+ readonly p?: number;
71
+ readonly coeffs?: readonly bigint[];
72
+ readonly summary?: readonly bigint[];
73
+ readonly discInv?: number;
74
+ readonly qDisc?: number;
75
+ readonly c1?: number;
76
+ readonly c0?: number;
77
+ readonly lagrangeSquares?: readonly [number, number, number, number];
78
+ }
79
+ /**
80
+ * Tate's universal Weierstrass discriminant `Δ(a_1, a_2, a_3, a_4, a_6)` over `Z`,
81
+ * valid in ALL characteristics `p >= 2` (including `p = 2` and `p = 3`).
82
+ */
83
+ export declare function computeTateDiscriminant(coeffs: WeierstrassCoeffs): bigint;
84
+ export declare function computeWeilTraceCertData(p: number, coeffsInput: readonly (number | bigint)[]): WeilCertResult;
85
+ /**
86
+ * `(discInv, (qDisc, (c1, (negC1, (c0, (negC0, (quadWits, (eta, (powSteps, (fiberWits, sq4))))))))))`
87
+ */
88
+ export declare function mkWeilWitnessDataTupleType(): Term;
89
+ export declare function buildWeilTraceCertWitnessTerm(solved: WeilCertResult, overrides?: ForgedWeilOverrides): {
90
+ readonly certTypeTerm: Term;
91
+ readonly certProofTerm: Term;
92
+ };
93
+ export declare function trySolveWeilTraceGoal(state: ProofState): boolean;
94
+ export declare function installLefschetzTacticsOnly(env: ElabEnv): ElabEnv;
95
+ /** `p = 2`: Supersingular `E_2 : y^2 + y = x^3` (`[0, 0, 1, 0, 0]`, `N_1 = 3, N_2 = 9, a_2 = 0`). */
96
+ export declare function buildEllipticF2SupersingularWeilSpec(): {
97
+ readonly p: number;
98
+ readonly coeffs: WeierstrassCoeffs;
99
+ };
100
+ /** `p = 3`: Gauss CM `E_3 : y^2 = x^3 - x` (`[0, 0, 0, -1, 0]`, `N_1 = 4, N_2 = 16, a_3 = 0`). */
101
+ export declare function buildEllipticF3GaussWeilSpec(): {
102
+ readonly p: number;
103
+ readonly coeffs: WeierstrassCoeffs;
104
+ };
105
+ /** `p = 5`: Ordinary `E_5 : y^2 = x^3 + x + 1` (`[0, 0, 0, 1, 1]`, `N_1 = 9, N_2 = 27, a_5 = -3`). */
106
+ export declare function buildEllipticF5OrdinaryWeilSpec(): {
107
+ readonly p: number;
108
+ readonly coeffs: WeierstrassCoeffs;
109
+ };
110
+ /** `p = 7`: Eisenstein CM `E_7 : y^2 = x^3 + 2` (`[0, 0, 0, 0, 2]`, `N_1 = 9, N_2 = 63, a_7 = -1`). */
111
+ export declare function buildEllipticF7EisensteinWeilSpec(): {
112
+ readonly p: number;
113
+ readonly coeffs: WeierstrassCoeffs;
114
+ };