recursive-set 1.0.0 → 1.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.
- package/{src/index.ts → dist/cjs/index.js} +306 -344
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/esm/index.d.ts +129 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +299 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +17 -11
- package/test.ts +0 -115
- package/tsconfig.json +0 -19
|
@@ -1,344 +1,306 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Check if adding element would violate Foundation axiom
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
const visited = new Set
|
|
46
|
-
const toCheck
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
*
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
// ===
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
return el.toString();
|
|
308
|
-
}
|
|
309
|
-
return String(el);
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
return `{${elements.join(", ")}}`;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* For console.log
|
|
317
|
-
*/
|
|
318
|
-
[Symbol.for('nodejs.util.inspect.custom')](): string {
|
|
319
|
-
return this.toString();
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// === Helper Functions ===
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Create empty set (Null Set axiom)
|
|
327
|
-
*/
|
|
328
|
-
export function emptySet<T = any>(): RecursiveSet<T> {
|
|
329
|
-
return new RecursiveSet<T>();
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Create singleton set
|
|
334
|
-
*/
|
|
335
|
-
export function singleton<T>(element: T): RecursiveSet<T> {
|
|
336
|
-
return new RecursiveSet<T>(element);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Create set from iterable
|
|
341
|
-
*/
|
|
342
|
-
export function fromIterable<T>(iterable: Iterable<T>): RecursiveSet<T> {
|
|
343
|
-
return new RecursiveSet<T>(...iterable);
|
|
344
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module recursive-set
|
|
4
|
+
* A mutable recursive set implementation enforcing Cantor's ZFC axioms
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.RecursiveSet = void 0;
|
|
8
|
+
exports.emptySet = emptySet;
|
|
9
|
+
exports.singleton = singleton;
|
|
10
|
+
exports.fromIterable = fromIterable;
|
|
11
|
+
/**
|
|
12
|
+
* RecursiveSet: Mutable set with arbitrary nesting depth
|
|
13
|
+
*
|
|
14
|
+
* Enforced ZFC Axioms (as class invariants):
|
|
15
|
+
* - Extensionality: Sets with same elements are equal
|
|
16
|
+
* - Foundation (Regularity): No membership cycles allowed
|
|
17
|
+
* - Power Set: Can construct 𝒫(A) for any set A
|
|
18
|
+
* - Union: Can construct A ∪ B for any sets A, B
|
|
19
|
+
* - Pairing: Can construct {a, b} for any elements a, b
|
|
20
|
+
*/
|
|
21
|
+
class RecursiveSet {
|
|
22
|
+
_elements;
|
|
23
|
+
constructor(...elements) {
|
|
24
|
+
this._elements = new Set();
|
|
25
|
+
for (const el of elements) {
|
|
26
|
+
this._addElement(el);
|
|
27
|
+
}
|
|
28
|
+
this._checkInvariants();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Internal: Add element with cycle detection (Foundation axiom)
|
|
32
|
+
*/
|
|
33
|
+
_addElement(el) {
|
|
34
|
+
if (el instanceof RecursiveSet) {
|
|
35
|
+
if (this._wouldCreateCycle(el)) {
|
|
36
|
+
throw new Error("Foundation axiom violated: adding this element would create a membership cycle");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
this._elements.add(el);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if adding element would violate Foundation axiom
|
|
43
|
+
*/
|
|
44
|
+
_wouldCreateCycle(element) {
|
|
45
|
+
const visited = new Set();
|
|
46
|
+
const toCheck = [element];
|
|
47
|
+
while (toCheck.length > 0) {
|
|
48
|
+
const current = toCheck.pop();
|
|
49
|
+
if (current === this) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (visited.has(current)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
visited.add(current);
|
|
56
|
+
for (const el of current._elements) {
|
|
57
|
+
if (el instanceof RecursiveSet) {
|
|
58
|
+
toCheck.push(el);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Verify class invariants (Design by Contract)
|
|
66
|
+
*/
|
|
67
|
+
_checkInvariants() {
|
|
68
|
+
// Extensionality: enforced by Set semantics
|
|
69
|
+
// Foundation: enforced by _wouldCreateCycle
|
|
70
|
+
// Well-definedness: enforced by TypeScript type system
|
|
71
|
+
// Additional runtime checks can be added here
|
|
72
|
+
if (process.env.NODE_ENV === 'development') {
|
|
73
|
+
// More expensive checks only in development
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// === Mutable Operations ===
|
|
77
|
+
/**
|
|
78
|
+
* Add element to this set (Pairing axiom)
|
|
79
|
+
* @returns this for method chaining
|
|
80
|
+
*/
|
|
81
|
+
add(element) {
|
|
82
|
+
this._addElement(element);
|
|
83
|
+
this._checkInvariants();
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Remove element from this set
|
|
88
|
+
* @returns this for method chaining
|
|
89
|
+
*/
|
|
90
|
+
remove(element) {
|
|
91
|
+
this._elements.delete(element);
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Remove all elements
|
|
96
|
+
* @returns this for method chaining
|
|
97
|
+
*/
|
|
98
|
+
clear() {
|
|
99
|
+
this._elements.clear();
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
// === Immutable Operations (return new sets) ===
|
|
103
|
+
/**
|
|
104
|
+
* Union of two sets (Union axiom)
|
|
105
|
+
* Returns A ∪ B
|
|
106
|
+
*/
|
|
107
|
+
union(other) {
|
|
108
|
+
const result = new RecursiveSet();
|
|
109
|
+
result._elements = new Set([...this._elements, ...other._elements]);
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Intersection of two sets
|
|
114
|
+
* Returns A ∩ B
|
|
115
|
+
*/
|
|
116
|
+
intersection(other) {
|
|
117
|
+
const result = new RecursiveSet();
|
|
118
|
+
for (const el of this._elements) {
|
|
119
|
+
if (other.has(el)) {
|
|
120
|
+
result._elements.add(el);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Set difference
|
|
127
|
+
* Returns A \ B (elements in A but not in B)
|
|
128
|
+
*/
|
|
129
|
+
difference(other) {
|
|
130
|
+
const result = new RecursiveSet();
|
|
131
|
+
for (const el of this._elements) {
|
|
132
|
+
if (!other.has(el)) {
|
|
133
|
+
result._elements.add(el);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Symmetric difference
|
|
140
|
+
* Returns A △ B (elements in either but not both)
|
|
141
|
+
*/
|
|
142
|
+
symmetricDifference(other) {
|
|
143
|
+
return this.union(other).difference(this.intersection(other));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Power set construction (Power Set axiom)
|
|
147
|
+
* Returns 𝒫(A) - set of all subsets
|
|
148
|
+
*/
|
|
149
|
+
powerset() {
|
|
150
|
+
const elements = Array.from(this._elements);
|
|
151
|
+
const subsets = [];
|
|
152
|
+
// Generate all 2^n subsets
|
|
153
|
+
const n = elements.length;
|
|
154
|
+
for (let i = 0; i < (1 << n); i++) {
|
|
155
|
+
const subset = new RecursiveSet();
|
|
156
|
+
for (let j = 0; j < n; j++) {
|
|
157
|
+
if (i & (1 << j)) {
|
|
158
|
+
subset._elements.add(elements[j]);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
subsets.push(subset);
|
|
162
|
+
}
|
|
163
|
+
return new RecursiveSet(...subsets);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Cartesian product
|
|
167
|
+
* Returns A × B as set of ordered pairs {{a}, {a,b}}
|
|
168
|
+
*/
|
|
169
|
+
cartesianProduct(other) {
|
|
170
|
+
const pairs = [];
|
|
171
|
+
for (const x of this._elements) {
|
|
172
|
+
for (const y of other._elements) {
|
|
173
|
+
// Kuratowski ordered pair: (x,y) := {{x}, {x,y}}
|
|
174
|
+
const pair = new RecursiveSet(new RecursiveSet(x), new RecursiveSet(x, y));
|
|
175
|
+
pairs.push(pair);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return new RecursiveSet(...pairs);
|
|
179
|
+
}
|
|
180
|
+
// === Predicates ===
|
|
181
|
+
/**
|
|
182
|
+
* Check membership (∈)
|
|
183
|
+
*/
|
|
184
|
+
has(element) {
|
|
185
|
+
return this._elements.has(element);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Check if subset (⊆)
|
|
189
|
+
*/
|
|
190
|
+
isSubset(other) {
|
|
191
|
+
for (const el of this._elements) {
|
|
192
|
+
if (!other.has(el)) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Check if superset (⊇)
|
|
200
|
+
*/
|
|
201
|
+
isSuperset(other) {
|
|
202
|
+
return other.isSubset(this);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Check if proper subset (⊂)
|
|
206
|
+
*/
|
|
207
|
+
isProperSubset(other) {
|
|
208
|
+
return this.isSubset(other) && !this.equals(other);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Check if empty set
|
|
212
|
+
*/
|
|
213
|
+
isEmpty() {
|
|
214
|
+
return this._elements.size === 0;
|
|
215
|
+
}
|
|
216
|
+
// === Extensionality (Equality) ===
|
|
217
|
+
/**
|
|
218
|
+
* Structural equality (Extensionality axiom)
|
|
219
|
+
* Two sets are equal iff they have the same elements
|
|
220
|
+
*/
|
|
221
|
+
equals(other) {
|
|
222
|
+
if (this._elements.size !== other._elements.size) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
for (const el of this._elements) {
|
|
226
|
+
if (el instanceof RecursiveSet) {
|
|
227
|
+
// Deep comparison for nested sets
|
|
228
|
+
let found = false;
|
|
229
|
+
for (const otherEl of other._elements) {
|
|
230
|
+
if (otherEl instanceof RecursiveSet && el.equals(otherEl)) {
|
|
231
|
+
found = true;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (!found)
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
if (!other.has(el))
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
// === Utility ===
|
|
246
|
+
/**
|
|
247
|
+
* Cardinality |A|
|
|
248
|
+
*/
|
|
249
|
+
get size() {
|
|
250
|
+
return this._elements.size;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Convert to native Set (shallow)
|
|
254
|
+
*/
|
|
255
|
+
toSet() {
|
|
256
|
+
return new Set(this._elements);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Iterate over elements
|
|
260
|
+
*/
|
|
261
|
+
*[Symbol.iterator]() {
|
|
262
|
+
yield* this._elements;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Pretty print with mathematical notation
|
|
266
|
+
*/
|
|
267
|
+
toString() {
|
|
268
|
+
if (this.isEmpty()) {
|
|
269
|
+
return "∅";
|
|
270
|
+
}
|
|
271
|
+
const elements = Array.from(this._elements).map(el => {
|
|
272
|
+
if (el instanceof RecursiveSet) {
|
|
273
|
+
return el.toString();
|
|
274
|
+
}
|
|
275
|
+
return String(el);
|
|
276
|
+
});
|
|
277
|
+
return `{${elements.join(", ")}}`;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* For console.log
|
|
281
|
+
*/
|
|
282
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
283
|
+
return this.toString();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
exports.RecursiveSet = RecursiveSet;
|
|
287
|
+
// === Helper Functions ===
|
|
288
|
+
/**
|
|
289
|
+
* Create empty set (Null Set axiom)
|
|
290
|
+
*/
|
|
291
|
+
function emptySet() {
|
|
292
|
+
return new RecursiveSet();
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Create singleton set
|
|
296
|
+
*/
|
|
297
|
+
function singleton(element) {
|
|
298
|
+
return new RecursiveSet(element);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Create set from iterable
|
|
302
|
+
*/
|
|
303
|
+
function fromIterable(iterable) {
|
|
304
|
+
return new RecursiveSet(...iterable);
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAoUH,4BAEC;AAKD,8BAEC;AAKD,oCAEC;AAlVD;;;;;;;;;GASG;AACH,MAAa,YAAY;IACb,SAAS,CAA2B;IAE5C,YAAY,GAAG,QAAoC;QAC/C,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE,CAAC;YACxB,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACzB,CAAC;QACD,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,EAAuB;QACvC,IAAI,EAAE,YAAY,YAAY,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C,GAAG,CAAC,4BAA4B,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC3B,CAAC;CACJ;AAjTD,oCAiTC;AAED,2BAA2B;AAE3B;;GAEG;AACH,SAAgB,QAAQ;IACpB,OAAO,IAAI,YAAY,EAAK,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAI,OAAU;IACnC,OAAO,IAAI,YAAY,CAAI,OAAO,CAAC,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAI,QAAqB;IACjD,OAAO,IAAI,YAAY,CAAI,GAAG,QAAQ,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module recursive-set
|
|
3
|
+
* A mutable recursive set implementation enforcing Cantor's ZFC axioms
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* RecursiveSet: Mutable set with arbitrary nesting depth
|
|
7
|
+
*
|
|
8
|
+
* Enforced ZFC Axioms (as class invariants):
|
|
9
|
+
* - Extensionality: Sets with same elements are equal
|
|
10
|
+
* - Foundation (Regularity): No membership cycles allowed
|
|
11
|
+
* - Power Set: Can construct 𝒫(A) for any set A
|
|
12
|
+
* - Union: Can construct A ∪ B for any sets A, B
|
|
13
|
+
* - Pairing: Can construct {a, b} for any elements a, b
|
|
14
|
+
*/
|
|
15
|
+
export declare class RecursiveSet<T = any> {
|
|
16
|
+
private _elements;
|
|
17
|
+
constructor(...elements: Array<T | RecursiveSet<T>>);
|
|
18
|
+
/**
|
|
19
|
+
* Internal: Add element with cycle detection (Foundation axiom)
|
|
20
|
+
*/
|
|
21
|
+
private _addElement;
|
|
22
|
+
/**
|
|
23
|
+
* Check if adding element would violate Foundation axiom
|
|
24
|
+
*/
|
|
25
|
+
private _wouldCreateCycle;
|
|
26
|
+
/**
|
|
27
|
+
* Verify class invariants (Design by Contract)
|
|
28
|
+
*/
|
|
29
|
+
private _checkInvariants;
|
|
30
|
+
/**
|
|
31
|
+
* Add element to this set (Pairing axiom)
|
|
32
|
+
* @returns this for method chaining
|
|
33
|
+
*/
|
|
34
|
+
add(element: T | RecursiveSet<T>): this;
|
|
35
|
+
/**
|
|
36
|
+
* Remove element from this set
|
|
37
|
+
* @returns this for method chaining
|
|
38
|
+
*/
|
|
39
|
+
remove(element: T | RecursiveSet<T>): this;
|
|
40
|
+
/**
|
|
41
|
+
* Remove all elements
|
|
42
|
+
* @returns this for method chaining
|
|
43
|
+
*/
|
|
44
|
+
clear(): this;
|
|
45
|
+
/**
|
|
46
|
+
* Union of two sets (Union axiom)
|
|
47
|
+
* Returns A ∪ B
|
|
48
|
+
*/
|
|
49
|
+
union(other: RecursiveSet<T>): RecursiveSet<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Intersection of two sets
|
|
52
|
+
* Returns A ∩ B
|
|
53
|
+
*/
|
|
54
|
+
intersection(other: RecursiveSet<T>): RecursiveSet<T>;
|
|
55
|
+
/**
|
|
56
|
+
* Set difference
|
|
57
|
+
* Returns A \ B (elements in A but not in B)
|
|
58
|
+
*/
|
|
59
|
+
difference(other: RecursiveSet<T>): RecursiveSet<T>;
|
|
60
|
+
/**
|
|
61
|
+
* Symmetric difference
|
|
62
|
+
* Returns A △ B (elements in either but not both)
|
|
63
|
+
*/
|
|
64
|
+
symmetricDifference(other: RecursiveSet<T>): RecursiveSet<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Power set construction (Power Set axiom)
|
|
67
|
+
* Returns 𝒫(A) - set of all subsets
|
|
68
|
+
*/
|
|
69
|
+
powerset(): RecursiveSet<RecursiveSet<T>>;
|
|
70
|
+
/**
|
|
71
|
+
* Cartesian product
|
|
72
|
+
* Returns A × B as set of ordered pairs {{a}, {a,b}}
|
|
73
|
+
*/
|
|
74
|
+
cartesianProduct<U>(other: RecursiveSet<U>): RecursiveSet<RecursiveSet<T | U>>;
|
|
75
|
+
/**
|
|
76
|
+
* Check membership (∈)
|
|
77
|
+
*/
|
|
78
|
+
has(element: T | RecursiveSet<T>): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Check if subset (⊆)
|
|
81
|
+
*/
|
|
82
|
+
isSubset(other: RecursiveSet<T>): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Check if superset (⊇)
|
|
85
|
+
*/
|
|
86
|
+
isSuperset(other: RecursiveSet<T>): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Check if proper subset (⊂)
|
|
89
|
+
*/
|
|
90
|
+
isProperSubset(other: RecursiveSet<T>): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Check if empty set
|
|
93
|
+
*/
|
|
94
|
+
isEmpty(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Structural equality (Extensionality axiom)
|
|
97
|
+
* Two sets are equal iff they have the same elements
|
|
98
|
+
*/
|
|
99
|
+
equals(other: RecursiveSet<T>): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Cardinality |A|
|
|
102
|
+
*/
|
|
103
|
+
get size(): number;
|
|
104
|
+
/**
|
|
105
|
+
* Convert to native Set (shallow)
|
|
106
|
+
*/
|
|
107
|
+
toSet(): Set<T | RecursiveSet<T>>;
|
|
108
|
+
/**
|
|
109
|
+
* Iterate over elements
|
|
110
|
+
*/
|
|
111
|
+
[Symbol.iterator](): Iterator<T | RecursiveSet<T>>;
|
|
112
|
+
/**
|
|
113
|
+
* Pretty print with mathematical notation
|
|
114
|
+
*/
|
|
115
|
+
toString(): string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Create empty set (Null Set axiom)
|
|
119
|
+
*/
|
|
120
|
+
export declare function emptySet<T = any>(): RecursiveSet<T>;
|
|
121
|
+
/**
|
|
122
|
+
* Create singleton set
|
|
123
|
+
*/
|
|
124
|
+
export declare function singleton<T>(element: T): RecursiveSet<T>;
|
|
125
|
+
/**
|
|
126
|
+
* Create set from iterable
|
|
127
|
+
*/
|
|
128
|
+
export declare function fromIterable<T>(iterable: Iter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ing Cantor's ZFC axioms
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* RecursiveSet: Mutable set with arbitrary nesting depth
|
|
7
|
+
*
|
|
8
|
+
* Enforced ZFC Axioms (as class invariants):
|
|
9
|
+
* - Extensionality: Sets with same elements are equal
|
|
10
|
+
* - Foundation (Regularity): No membership cycles allowed
|
|
11
|
+
* - Power Set: Can construct 𝒫(A) for any set A
|
|
12
|
+
* - Union: Can construct A ∪ B for any sets A, B
|
|
13
|
+
* - Pairing: Can construct {a, b} for any elements a, b
|
|
14
|
+
*/
|
|
15
|
+
export class RecursiveSet {
|
|
16
|
+
_elements;
|
|
17
|
+
constructor(...elements) {
|
|
18
|
+
this._elements = new Set();
|
|
19
|
+
for (const el of elements) {
|
|
20
|
+
this._addElement(el);
|
|
21
|
+
}
|
|
22
|
+
this._checkInvariants();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Internal: Add element with cycle detection (Foundation axiom)
|
|
26
|
+
*/
|
|
27
|
+
_addElement(el) {
|
|
28
|
+
if (el instanceof RecursiveSet) {
|
|
29
|
+
if (this._wouldCreateCycle(el)) {
|
|
30
|
+
throw new Error("Foundation axiom violated: adding this element would create a membership cycle");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
this._elements.add(el);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if adding element would violate Foundation axiom
|
|
37
|
+
*/
|
|
38
|
+
_wouldCreateCycle(element) {
|
|
39
|
+
const visited = new Set();
|
|
40
|
+
const toCheck = [element];
|
|
41
|
+
while (toCheck.length > 0) {
|
|
42
|
+
const current = toCheck.pop();
|
|
43
|
+
if (current === this) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (visited.has(current)) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
visited.add(current);
|
|
50
|
+
for (const el of current._elements) {
|
|
51
|
+
if (el instanceof RecursiveSet) {
|
|
52
|
+
toCheck.push(el);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Verify class invariants (Design by Contract)
|
|
60
|
+
*/
|
|
61
|
+
_checkInvariants() {
|
|
62
|
+
// Extensionality: enforced by Set semantics
|
|
63
|
+
// Foundation: enforced by _wouldCreateCycle
|
|
64
|
+
// Well-definedness: enforced by TypeScript type system
|
|
65
|
+
// Additional runtime checks can be added here
|
|
66
|
+
if (process.env.NODE_ENV === 'development') {
|
|
67
|
+
// More expensive checks only in development
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// === Mutable Operations ===
|
|
71
|
+
/**
|
|
72
|
+
* Add element to this set (Pairing axiom)
|
|
73
|
+
* @returns this for method chaining
|
|
74
|
+
*/
|
|
75
|
+
add(element) {
|
|
76
|
+
this._addElement(element);
|
|
77
|
+
this._checkInvariants();
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Remove element from this set
|
|
82
|
+
* @returns this for method chaining
|
|
83
|
+
*/
|
|
84
|
+
remove(element) {
|
|
85
|
+
this._elements.delete(element);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Remove all elements
|
|
90
|
+
* @returns this for method chaining
|
|
91
|
+
*/
|
|
92
|
+
clear() {
|
|
93
|
+
this._elements.clear();
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
// === Immutable Operations (return new sets) ===
|
|
97
|
+
/**
|
|
98
|
+
* Union of two sets (Union axiom)
|
|
99
|
+
* Returns A ∪ B
|
|
100
|
+
*/
|
|
101
|
+
union(other) {
|
|
102
|
+
const result = new RecursiveSet();
|
|
103
|
+
result._elements = new Set([...this._elements, ...other._elements]);
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Intersection of two sets
|
|
108
|
+
* Returns A ∩ B
|
|
109
|
+
*/
|
|
110
|
+
intersection(other) {
|
|
111
|
+
const result = new RecursiveSet();
|
|
112
|
+
for (const el of this._elements) {
|
|
113
|
+
if (other.has(el)) {
|
|
114
|
+
result._elements.add(el);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Set difference
|
|
121
|
+
* Returns A \ B (elements in A but not in B)
|
|
122
|
+
*/
|
|
123
|
+
difference(other) {
|
|
124
|
+
const result = new RecursiveSet();
|
|
125
|
+
for (const el of this._elements) {
|
|
126
|
+
if (!other.has(el)) {
|
|
127
|
+
result._elements.add(el);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Symmetric difference
|
|
134
|
+
* Returns A △ B (elements in either but not both)
|
|
135
|
+
*/
|
|
136
|
+
symmetricDifference(other) {
|
|
137
|
+
return this.union(other).difference(this.intersection(other));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Power set construction (Power Set axiom)
|
|
141
|
+
* Returns 𝒫(A) - set of all subsets
|
|
142
|
+
*/
|
|
143
|
+
powerset() {
|
|
144
|
+
const elements = Array.from(this._elements);
|
|
145
|
+
const subsets = [];
|
|
146
|
+
// Generate all 2^n subsets
|
|
147
|
+
const n = elements.length;
|
|
148
|
+
for (let i = 0; i < (1 << n); i++) {
|
|
149
|
+
const subset = new RecursiveSet();
|
|
150
|
+
for (let j = 0; j < n; j++) {
|
|
151
|
+
if (i & (1 << j)) {
|
|
152
|
+
subset._elements.add(elements[j]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
subsets.push(subset);
|
|
156
|
+
}
|
|
157
|
+
return new RecursiveSet(...subsets);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Cartesian product
|
|
161
|
+
* Returns A × B as set of ordered pairs {{a}, {a,b}}
|
|
162
|
+
*/
|
|
163
|
+
cartesianProduct(other) {
|
|
164
|
+
const pairs = [];
|
|
165
|
+
for (const x of this._elements) {
|
|
166
|
+
for (const y of other._elements) {
|
|
167
|
+
// Kuratowski ordered pair: (x,y) := {{x}, {x,y}}
|
|
168
|
+
const pair = new RecursiveSet(new RecursiveSet(x), new RecursiveSet(x, y));
|
|
169
|
+
pairs.push(pair);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return new RecursiveSet(...pairs);
|
|
173
|
+
}
|
|
174
|
+
// === Predicates ===
|
|
175
|
+
/**
|
|
176
|
+
* Check membership (∈)
|
|
177
|
+
*/
|
|
178
|
+
has(element) {
|
|
179
|
+
return this._elements.has(element);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Check if subset (⊆)
|
|
183
|
+
*/
|
|
184
|
+
isSubset(other) {
|
|
185
|
+
for (const el of this._elements) {
|
|
186
|
+
if (!other.has(el)) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Check if superset (⊇)
|
|
194
|
+
*/
|
|
195
|
+
isSuperset(other) {
|
|
196
|
+
return other.isSubset(this);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Check if proper subset (⊂)
|
|
200
|
+
*/
|
|
201
|
+
isProperSubset(other) {
|
|
202
|
+
return this.isSubset(other) && !this.equals(other);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Check if empty set
|
|
206
|
+
*/
|
|
207
|
+
isEmpty() {
|
|
208
|
+
return this._elements.size === 0;
|
|
209
|
+
}
|
|
210
|
+
// === Extensionality (Equality) ===
|
|
211
|
+
/**
|
|
212
|
+
* Structural equality (Extensionality axiom)
|
|
213
|
+
* Two sets are equal iff they have the same elements
|
|
214
|
+
*/
|
|
215
|
+
equals(other) {
|
|
216
|
+
if (this._elements.size !== other._elements.size) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
for (const el of this._elements) {
|
|
220
|
+
if (el instanceof RecursiveSet) {
|
|
221
|
+
// Deep comparison for nested sets
|
|
222
|
+
let found = false;
|
|
223
|
+
for (const otherEl of other._elements) {
|
|
224
|
+
if (otherEl instanceof RecursiveSet && el.equals(otherEl)) {
|
|
225
|
+
found = true;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (!found)
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
if (!other.has(el))
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
// === Utility ===
|
|
240
|
+
/**
|
|
241
|
+
* Cardinality |A|
|
|
242
|
+
*/
|
|
243
|
+
get size() {
|
|
244
|
+
return this._elements.size;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Convert to native Set (shallow)
|
|
248
|
+
*/
|
|
249
|
+
toSet() {
|
|
250
|
+
return new Set(this._elements);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Iterate over elements
|
|
254
|
+
*/
|
|
255
|
+
*[Symbol.iterator]() {
|
|
256
|
+
yield* this._elements;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Pretty print with mathematical notation
|
|
260
|
+
*/
|
|
261
|
+
toString() {
|
|
262
|
+
if (this.isEmpty()) {
|
|
263
|
+
return "∅";
|
|
264
|
+
}
|
|
265
|
+
const elements = Array.from(this._elements).map(el => {
|
|
266
|
+
if (el instanceof RecursiveSet) {
|
|
267
|
+
return el.toString();
|
|
268
|
+
}
|
|
269
|
+
return String(el);
|
|
270
|
+
});
|
|
271
|
+
return `{${elements.join(", ")}}`;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* For console.log
|
|
275
|
+
*/
|
|
276
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
277
|
+
return this.toString();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// === Helper Functions ===
|
|
281
|
+
/**
|
|
282
|
+
* Create empty set (Null Set axiom)
|
|
283
|
+
*/
|
|
284
|
+
export function emptySet() {
|
|
285
|
+
return new RecursiveSet();
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Create singleton set
|
|
289
|
+
*/
|
|
290
|
+
export function singleton(element) {
|
|
291
|
+
return new RecursiveSet(element);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Create set from iterable
|
|
295
|
+
*/
|
|
296
|
+
export function fromIterable(iterable) {
|
|
297
|
+
return new RecursiveSet(...iterable);
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,MAAM,OAAO,YAAY;IACb,SAAS,CAA2B;IAE5C,YAAY,GAAG,QAAoC;QAC/C,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE,CAAC;YACxB,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACzB,CAAC;QACD,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,EAAuB;QACvC,IAAI,EAAE,YAAY,YAAY,EAAE,CAAC;YAC7B,IAAI,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CACX,gFAAgF,CACnF,CAAC;YACN,CAAC;QACL,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACK,iBAAiB,CAAC,OAAwB;QAC9C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;QAC7C,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ACH,MAAM,UAAU,YAAY,CAAI,QAAqB;IACjD,OAAO,IAAI,YAAY,CAAI,GAAG,QAAQ,CAAC,CAAC;AAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "recursive-set",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Mutable recursive sets with ZFC axioms for TypeScript",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"types": "./dist/esm/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"types": "./dist/esm/index.d.ts",
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/cjs/index.js"
|
|
12
13
|
}
|
|
13
14
|
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
14
18
|
"scripts": {
|
|
15
|
-
"
|
|
19
|
+
"prepublishOnly": "npm run build",
|
|
20
|
+
"build": "rimraf dist && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/postbuild.cjs",
|
|
16
21
|
"watch": "tsc --watch",
|
|
17
|
-
"clean": "
|
|
22
|
+
"clean": "rimraf dist",
|
|
18
23
|
"test": "tsx test.ts"
|
|
19
24
|
},
|
|
20
25
|
"keywords": [
|
|
@@ -31,15 +36,16 @@
|
|
|
31
36
|
"license": "MIT",
|
|
32
37
|
"repository": {
|
|
33
38
|
"type": "git",
|
|
34
|
-
"url": "git+https://github.com
|
|
39
|
+
"url": "git+https://github.com/cstrerath/recursive-set.git"
|
|
35
40
|
},
|
|
36
41
|
"bugs": {
|
|
37
|
-
"url": "https://github.com
|
|
42
|
+
"url": "https://github.com/cstrerath/recursive-set/issues"
|
|
38
43
|
},
|
|
39
|
-
"homepage": "https://github.com
|
|
44
|
+
"homepage": "https://github.com/cstrerath/recursive-set#readme",
|
|
40
45
|
"devDependencies": {
|
|
41
46
|
"@types/node": "^20.0.0",
|
|
47
|
+
"rimraf": "^6.1.2",
|
|
42
48
|
"tsx": "^4.20.6",
|
|
43
49
|
"typescript": "^5.6.0"
|
|
44
50
|
}
|
|
45
|
-
}
|
|
51
|
+
}
|
package/test.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { RecursiveSet } from './src/index.js';
|
|
2
|
-
|
|
3
|
-
console.log('=== RecursiveSet Test Suite ===\n');
|
|
4
|
-
|
|
5
|
-
// ============================================================================
|
|
6
|
-
// Test 1: Basic FSM State Sets
|
|
7
|
-
// ============================================================================
|
|
8
|
-
console.log('--- Test 1: Basic State Sets ---');
|
|
9
|
-
const q0 = "q0";
|
|
10
|
-
const q1 = "q1";
|
|
11
|
-
const q2 = "q2";
|
|
12
|
-
const q3 = "q3";
|
|
13
|
-
|
|
14
|
-
const eqClass1 = new RecursiveSet(q0, q1);
|
|
15
|
-
const eqClass2 = new RecursiveSet(q2, q3);
|
|
16
|
-
console.log(`Equivalence class 1: ${eqClass1}`);
|
|
17
|
-
console.log(`Equivalence class 2: ${eqClass2}`);
|
|
18
|
-
console.log();
|
|
19
|
-
|
|
20
|
-
// ============================================================================
|
|
21
|
-
// Test 2: Sets of Sets (Equivalence Classes)
|
|
22
|
-
// ============================================================================
|
|
23
|
-
console.log('--- Test 2: Sets of Sets ---');
|
|
24
|
-
const eqClasses = new RecursiveSet(eqClass1, eqClass2);
|
|
25
|
-
console.log(`Equivalence classes: ${eqClasses}`);
|
|
26
|
-
console.log();
|
|
27
|
-
|
|
28
|
-
// ============================================================================
|
|
29
|
-
// Test 3: Mutability - Adding Elements
|
|
30
|
-
// ============================================================================
|
|
31
|
-
console.log('--- Test 3: Mutability ---');
|
|
32
|
-
const eqClass3 = new RecursiveSet("q4");
|
|
33
|
-
eqClasses.add(eqClass3);
|
|
34
|
-
console.log(`After adding {q4}: ${eqClasses}`);
|
|
35
|
-
console.log();
|
|
36
|
-
|
|
37
|
-
// ============================================================================
|
|
38
|
-
// Test 4: Extensionality (Structural Equality)
|
|
39
|
-
// ============================================================================
|
|
40
|
-
console.log('--- Test 4: Extensionality Axiom ---');
|
|
41
|
-
const eqClass1_copy = new RecursiveSet("q0", "q1");
|
|
42
|
-
console.log(`eqClass1: ${eqClass1}`);
|
|
43
|
-
console.log(`eqClass1_copy: ${eqClass1_copy}`);
|
|
44
|
-
console.log(`Are they equal? ${eqClass1.equals(eqClass1_copy)}`);
|
|
45
|
-
console.log();
|
|
46
|
-
|
|
47
|
-
// ============================================================================
|
|
48
|
-
// Test 5: Empty Set Handling
|
|
49
|
-
// ============================================================================
|
|
50
|
-
console.log('--- Test 5: Empty Set ---');
|
|
51
|
-
const emptyClass = new RecursiveSet();
|
|
52
|
-
const eqClassesWithEmpty = new RecursiveSet(eqClass1, emptyClass);
|
|
53
|
-
console.log(`With empty class: ${eqClassesWithEmpty}`);
|
|
54
|
-
console.log();
|
|
55
|
-
|
|
56
|
-
// ============================================================================
|
|
57
|
-
// Test 6: Deep Nesting
|
|
58
|
-
// ============================================================================
|
|
59
|
-
console.log('--- Test 6: Deep Nesting ---');
|
|
60
|
-
const nested = new RecursiveSet(eqClasses, eqClassesWithEmpty);
|
|
61
|
-
console.log(`Nested structure: ${nested}`);
|
|
62
|
-
console.log();
|
|
63
|
-
|
|
64
|
-
// ============================================================================
|
|
65
|
-
// Test 7: Set Operations
|
|
66
|
-
// ============================================================================
|
|
67
|
-
console.log('--- Test 7: Set Operations ---');
|
|
68
|
-
const difference = eqClasses.difference(new RecursiveSet(eqClass2));
|
|
69
|
-
console.log(`eqClasses - {eqClass2} = ${difference}`);
|
|
70
|
-
|
|
71
|
-
const union = eqClass1.union(eqClass2);
|
|
72
|
-
console.log(`eqClass1 ∪ eqClass2 = ${union}`);
|
|
73
|
-
|
|
74
|
-
const intersection = new RecursiveSet(q0, q1, q2).intersection(new RecursiveSet(q1, q2, q3));
|
|
75
|
-
console.log(`{q0, q1, q2} ∩ {q1, q2, q3} = ${intersection}`);
|
|
76
|
-
console.log();
|
|
77
|
-
|
|
78
|
-
// ============================================================================
|
|
79
|
-
// Test 8: Power Set
|
|
80
|
-
// ============================================================================
|
|
81
|
-
console.log('--- Test 8: Power Set ---');
|
|
82
|
-
const small = new RecursiveSet(1, 2);
|
|
83
|
-
const power = small.powerset();
|
|
84
|
-
console.log(`𝒫({1, 2}) = ${power}`);
|
|
85
|
-
console.log();
|
|
86
|
-
|
|
87
|
-
// ============================================================================
|
|
88
|
-
// Test 9: Foundation Axiom (Cycle Detection)
|
|
89
|
-
// ============================================================================
|
|
90
|
-
console.log('--- Test 9: Foundation Axiom ---');
|
|
91
|
-
try {
|
|
92
|
-
const circular = new RecursiveSet(1, 2);
|
|
93
|
-
circular.add(circular);
|
|
94
|
-
console.log('❌ ERROR: Cycle should have been detected!');
|
|
95
|
-
} catch (e: any) {
|
|
96
|
-
console.log(`✓ Cycle detected: ${e.message}`);
|
|
97
|
-
}
|
|
98
|
-
console.log();
|
|
99
|
-
|
|
100
|
-
// ============================================================================
|
|
101
|
-
// Test 10: Subset Relations
|
|
102
|
-
// ============================================================================
|
|
103
|
-
console.log('--- Test 10: Subset Relations ---');
|
|
104
|
-
const setA = new RecursiveSet(1, 2, 3);
|
|
105
|
-
const setB = new RecursiveSet(1, 2);
|
|
106
|
-
console.log(`A = ${setA}`);
|
|
107
|
-
console.log(`B = ${setB}`);
|
|
108
|
-
console.log(`B ⊆ A? ${setB.isSubset(setA)}`);
|
|
109
|
-
console.log(`A ⊆ B? ${setA.isSubset(setB)}`);
|
|
110
|
-
console.log();
|
|
111
|
-
|
|
112
|
-
// ============================================================================
|
|
113
|
-
// Summary
|
|
114
|
-
// ============================================================================
|
|
115
|
-
console.log('=== All Tests Completed Successfully ✓ ===');
|
package/tsconfig.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022", /* Modern JavaScript */
|
|
4
|
-
"module": "ES2022", /* ESM modules */
|
|
5
|
-
"lib": ["ES2022"], /* Available APIs */
|
|
6
|
-
"outDir": "./dist", /* Compiled JS output directory */
|
|
7
|
-
"rootDir": "./src", /* TypeScript source files */
|
|
8
|
-
"declaration": true, /* Generate .d.ts type files */
|
|
9
|
-
"declarationMap": true, /* Source maps for types */
|
|
10
|
-
"sourceMap": true, /* Source maps for debugging */
|
|
11
|
-
"strict": true, /* Enable all strict checks */
|
|
12
|
-
"esModuleInterop": true, /* Better module compatibility */
|
|
13
|
-
"skipLibCheck": true, /* Faster compilation */
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
"moduleResolution": "node" /* Node.js module resolution */
|
|
16
|
-
},
|
|
17
|
-
"include": ["src/**/*"], /* Files to compile */
|
|
18
|
-
"exclude": ["node_modules", "dist"] /* Files to ignore */
|
|
19
|
-
}
|