@stevenvo780/st-lang 4.12.0 → 4.13.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.
- package/dist/reasoning/datalog/index.d.ts +131 -0
- package/dist/reasoning/datalog/index.d.ts.map +1 -0
- package/dist/reasoning/datalog/index.js +706 -0
- package/dist/reasoning/datalog/index.js.map +1 -0
- package/dist/reasoning/galois-fields/index.d.ts +29 -0
- package/dist/reasoning/galois-fields/index.d.ts.map +1 -0
- package/dist/reasoning/galois-fields/index.js +522 -0
- package/dist/reasoning/galois-fields/index.js.map +1 -0
- package/dist/reasoning/lattice/index.d.ts +165 -0
- package/dist/reasoning/lattice/index.d.ts.map +1 -0
- package/dist/reasoning/lattice/index.js +587 -0
- package/dist/reasoning/lattice/index.js.map +1 -0
- package/dist/reasoning/polynomial-ring/index.d.ts +30 -0
- package/dist/reasoning/polynomial-ring/index.d.ts.map +1 -0
- package/dist/reasoning/polynomial-ring/index.js +797 -0
- package/dist/reasoning/polynomial-ring/index.js.map +1 -0
- package/dist/tests/reasoning/datalog/datalog.test.d.ts +2 -0
- package/dist/tests/reasoning/datalog/datalog.test.d.ts.map +1 -0
- package/dist/tests/reasoning/datalog/datalog.test.js +333 -0
- package/dist/tests/reasoning/datalog/datalog.test.js.map +1 -0
- package/dist/tests/reasoning/galois-fields/galois-fields.test.d.ts +2 -0
- package/dist/tests/reasoning/galois-fields/galois-fields.test.d.ts.map +1 -0
- package/dist/tests/reasoning/galois-fields/galois-fields.test.js +226 -0
- package/dist/tests/reasoning/galois-fields/galois-fields.test.js.map +1 -0
- package/dist/tests/reasoning/lattice/lattice.test.d.ts +2 -0
- package/dist/tests/reasoning/lattice/lattice.test.d.ts.map +1 -0
- package/dist/tests/reasoning/lattice/lattice.test.js +238 -0
- package/dist/tests/reasoning/lattice/lattice.test.js.map +1 -0
- package/dist/tests/reasoning/polynomial-ring/polynomial-ring.test.d.ts +2 -0
- package/dist/tests/reasoning/polynomial-ring/polynomial-ring.test.d.ts.map +1 -0
- package/dist/tests/reasoning/polynomial-ring/polynomial-ring.test.js +230 -0
- package/dist/tests/reasoning/polynomial-ring/polynomial-ring.test.js.map +1 -0
- package/dist/tests/type-theory/lambda-cube/lambda-cube.test.d.ts +2 -0
- package/dist/tests/type-theory/lambda-cube/lambda-cube.test.d.ts.map +1 -0
- package/dist/tests/type-theory/lambda-cube/lambda-cube.test.js +266 -0
- package/dist/tests/type-theory/lambda-cube/lambda-cube.test.js.map +1 -0
- package/dist/type-theory/lambda-cube/erase.d.ts +26 -0
- package/dist/type-theory/lambda-cube/erase.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/erase.js +68 -0
- package/dist/type-theory/lambda-cube/erase.js.map +1 -0
- package/dist/type-theory/lambda-cube/examples.d.ts +59 -0
- package/dist/type-theory/lambda-cube/examples.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/examples.js +110 -0
- package/dist/type-theory/lambda-cube/examples.js.map +1 -0
- package/dist/type-theory/lambda-cube/index.d.ts +11 -0
- package/dist/type-theory/lambda-cube/index.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/index.js +64 -0
- package/dist/type-theory/lambda-cube/index.js.map +1 -0
- package/dist/type-theory/lambda-cube/normalize.d.ts +17 -0
- package/dist/type-theory/lambda-cube/normalize.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/normalize.js +134 -0
- package/dist/type-theory/lambda-cube/normalize.js.map +1 -0
- package/dist/type-theory/lambda-cube/rules.d.ts +26 -0
- package/dist/type-theory/lambda-cube/rules.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/rules.js +67 -0
- package/dist/type-theory/lambda-cube/rules.js.map +1 -0
- package/dist/type-theory/lambda-cube/typecheck.d.ts +20 -0
- package/dist/type-theory/lambda-cube/typecheck.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/typecheck.js +168 -0
- package/dist/type-theory/lambda-cube/typecheck.js.map +1 -0
- package/dist/type-theory/lambda-cube/types.d.ts +40 -0
- package/dist/type-theory/lambda-cube/types.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/types.js +192 -0
- package/dist/type-theory/lambda-cube/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finite lattice theory.
|
|
3
|
+
*
|
|
4
|
+
* A lattice is a poset (P, ≤) in which every pair of elements has both
|
|
5
|
+
* a least upper bound (join, ∨) and a greatest lower bound (meet, ∧).
|
|
6
|
+
*
|
|
7
|
+
* This module focuses on **finite** lattices: given the carrier set and
|
|
8
|
+
* a `leq` predicate, we derive join/meet exhaustively (O(n^3) per pair
|
|
9
|
+
* via direct search). That is enough for the structural checks
|
|
10
|
+
* downstream — distributivity, modularity, complementation, Heyting
|
|
11
|
+
* implication — which are themselves O(n^3) or O(n^4) and not meant
|
|
12
|
+
* for n ≫ 100.
|
|
13
|
+
*
|
|
14
|
+
* Notable theorems used:
|
|
15
|
+
* - Dedekind: a lattice is **modular** iff it has no sublattice
|
|
16
|
+
* isomorphic to the pentagon N5.
|
|
17
|
+
* - Birkhoff: a lattice is **distributive** iff it has no sublattice
|
|
18
|
+
* isomorphic to N5 *or* to the diamond M3.
|
|
19
|
+
*
|
|
20
|
+
* Equality of carrier elements is decided by *antisymmetry of leq*:
|
|
21
|
+
* `a === b` whenever `leq(a,b) && leq(b,a)`. This lets callers use
|
|
22
|
+
* structural elements like `Set<string>` without supplying their own
|
|
23
|
+
* equality predicate.
|
|
24
|
+
*/
|
|
25
|
+
export interface FiniteLattice<T> {
|
|
26
|
+
readonly elements: ReadonlyArray<T>;
|
|
27
|
+
readonly leq: (a: T, b: T) => boolean;
|
|
28
|
+
readonly join: (a: T, b: T) => T;
|
|
29
|
+
readonly meet: (a: T, b: T) => T;
|
|
30
|
+
readonly top: T;
|
|
31
|
+
readonly bottom: T;
|
|
32
|
+
}
|
|
33
|
+
declare const indexOf: <T>(L: FiniteLattice<T>, x: T) => number;
|
|
34
|
+
/**
|
|
35
|
+
* Check that (elements, leq) forms a lattice: poset axioms plus
|
|
36
|
+
* existence of join/meet for every pair.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isLattice<T>(elements: ReadonlyArray<T>, leq: (a: T, b: T) => boolean): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Build a FiniteLattice from carrier + order. Returns null if the
|
|
41
|
+
* structure is not a lattice (missing/non-unique join or meet, or
|
|
42
|
+
* the order itself is malformed).
|
|
43
|
+
*/
|
|
44
|
+
export declare function makeLattice<T>(elements: ReadonlyArray<T>, leq: (a: T, b: T) => boolean): FiniteLattice<T> | null;
|
|
45
|
+
/**
|
|
46
|
+
* Distributive: a ∧ (b ∨ c) = (a ∧ b) ∨ (a ∧ c) for all a,b,c.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isDistributive<T>(L: FiniteLattice<T>): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Modular: a ≤ c ⇒ a ∨ (b ∧ c) = (a ∨ b) ∧ c.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isModular<T>(L: FiniteLattice<T>): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Find a complement of `a`: some x with a ∨ x = ⊤ and a ∧ x = ⊥.
|
|
55
|
+
* Returns the first match (lattice may have multiple), or null.
|
|
56
|
+
*/
|
|
57
|
+
export declare function complement<T>(L: FiniteLattice<T>, a: T): T | null;
|
|
58
|
+
/**
|
|
59
|
+
* Complemented: every element has at least one complement.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isComplemented<T>(L: FiniteLattice<T>): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Boolean lattice: distributive + complemented.
|
|
64
|
+
* In finite Boolean lattices, complements are automatically unique.
|
|
65
|
+
*/
|
|
66
|
+
export declare function isBoolean<T>(L: FiniteLattice<T>): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Relative pseudo-complement of `a` with respect to `b`: the largest
|
|
69
|
+
* x such that a ∧ x ≤ b. Equivalently the Heyting implication a ⇒ b.
|
|
70
|
+
* Returns null if no largest x exists.
|
|
71
|
+
*/
|
|
72
|
+
export declare function relativeComplement<T>(L: FiniteLattice<T>, a: T, b: T): T | null;
|
|
73
|
+
/**
|
|
74
|
+
* Heyting algebra: distributive lattice in which every pair (a,b)
|
|
75
|
+
* has a relative pseudo-complement a ⇒ b.
|
|
76
|
+
*
|
|
77
|
+
* In finite lattices, distributivity is equivalent to existence of
|
|
78
|
+
* relative pseudo-complements, so any finite distributive lattice is
|
|
79
|
+
* automatically Heyting. We still check both for clarity.
|
|
80
|
+
*/
|
|
81
|
+
export declare function isHeyting<T>(L: FiniteLattice<T>): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Atoms: elements that cover ⊥ (i.e. ⊥ < a with no element strictly
|
|
84
|
+
* between).
|
|
85
|
+
*/
|
|
86
|
+
export declare function atoms<T>(L: FiniteLattice<T>): T[];
|
|
87
|
+
/**
|
|
88
|
+
* Coatoms: elements covered by ⊤.
|
|
89
|
+
*/
|
|
90
|
+
export declare function coatoms<T>(L: FiniteLattice<T>): T[];
|
|
91
|
+
/**
|
|
92
|
+
* Detect a sublattice isomorphic to the pentagon N5.
|
|
93
|
+
*
|
|
94
|
+
* N5 is the 5-element lattice on {⊥, a, b, c, ⊤} with:
|
|
95
|
+
* - ⊥ < a < c < ⊤ (a chain of length 3)
|
|
96
|
+
* - ⊥ < b < ⊤ (b incomparable to both a and c)
|
|
97
|
+
* - a ∧ b = ⊥, a ∨ b = ⊤, c ∧ b = ⊥, c ∨ b = ⊤.
|
|
98
|
+
*
|
|
99
|
+
* Equivalent to: there exist 5 distinct elements x0 < x1 < x2 and y,
|
|
100
|
+
* with y incomparable to x1 and to x2 minus x0, top = x2 ∨ y,
|
|
101
|
+
* bottom = x0 ∧ y, and y ∨ x1 = y ∨ x2, y ∧ x1 = y ∧ x2.
|
|
102
|
+
*/
|
|
103
|
+
export declare function containsPentagon<T>(L: FiniteLattice<T>): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Detect a sublattice isomorphic to the diamond M3.
|
|
106
|
+
*
|
|
107
|
+
* M3 is the 5-element lattice with one bottom, one top, and three
|
|
108
|
+
* mutually incomparable elements between, each pair joining to ⊤
|
|
109
|
+
* and meeting to ⊥.
|
|
110
|
+
*/
|
|
111
|
+
export declare function containsDiamond<T>(L: FiniteLattice<T>): boolean;
|
|
112
|
+
export interface DedekindAnalysis {
|
|
113
|
+
readonly distributive: boolean;
|
|
114
|
+
readonly modular: boolean;
|
|
115
|
+
readonly pentagonFree: boolean;
|
|
116
|
+
readonly diamondFree: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Dedekind / Birkhoff structural analysis. By the two classical
|
|
120
|
+
* theorems:
|
|
121
|
+
* modular ⇔ pentagon-free
|
|
122
|
+
* distributive ⇔ pentagon-free AND diamond-free
|
|
123
|
+
* We compute both algebraically and by sublattice search; the result
|
|
124
|
+
* agrees on well-formed finite lattices.
|
|
125
|
+
*/
|
|
126
|
+
export declare function dedekindAnalysis<T>(L: FiniteLattice<T>): DedekindAnalysis;
|
|
127
|
+
/**
|
|
128
|
+
* Power set lattice 2^S ordered by inclusion. For |S|=n this has
|
|
129
|
+
* 2^n elements; keep n small (≤ 6).
|
|
130
|
+
*/
|
|
131
|
+
export declare function powerSetLattice(baseElements: ReadonlyArray<string>): FiniteLattice<Set<string>>;
|
|
132
|
+
/**
|
|
133
|
+
* Divisors of n ordered by divisibility. (Lattice for any positive n.)
|
|
134
|
+
*/
|
|
135
|
+
export declare function divisibilityLattice(n: number): FiniteLattice<number>;
|
|
136
|
+
/**
|
|
137
|
+
* Chain of n elements 0 < 1 < ... < n-1.
|
|
138
|
+
*/
|
|
139
|
+
export declare function chain(n: number): FiniteLattice<number>;
|
|
140
|
+
/**
|
|
141
|
+
* Pentagon N5: the classical non-modular 5-element lattice.
|
|
142
|
+
*
|
|
143
|
+
* Hasse diagram:
|
|
144
|
+
* T
|
|
145
|
+
* / \
|
|
146
|
+
* c b
|
|
147
|
+
* | |
|
|
148
|
+
* a |
|
|
149
|
+
* \ /
|
|
150
|
+
* B
|
|
151
|
+
*/
|
|
152
|
+
export declare function pentagonN5(): FiniteLattice<string>;
|
|
153
|
+
/**
|
|
154
|
+
* Diamond M3: modular but not distributive 5-element lattice.
|
|
155
|
+
*
|
|
156
|
+
* Hasse diagram:
|
|
157
|
+
* T
|
|
158
|
+
* / | \
|
|
159
|
+
* a b c
|
|
160
|
+
* \ | /
|
|
161
|
+
* B
|
|
162
|
+
*/
|
|
163
|
+
export declare function diamondM3(): FiniteLattice<string>;
|
|
164
|
+
export { indexOf as _indexOfElement };
|
|
165
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reasoning/lattice/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACpC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IAChB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;CACpB;AAID,QAAA,MAAM,OAAO,GAAI,CAAC,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,KAAG,MAK/C,CAAC;AAiDF;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,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