recursive-set 1.0.1 → 2.0.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/README.md CHANGED
@@ -21,6 +21,20 @@ Supports arbitrary nesting, detects cycles (Foundation axiom), and includes all
21
21
 
22
22
  ---
23
23
 
24
+ ## Implementation Details
25
+
26
+ This library enforces strict **ZFC Set Theory** semantics, differing from native JavaScript `Set`s:
27
+
28
+ - **Extensionality:** Two sets are considered equal if they contain the same elements, regardless of object reference identity.
29
+ - Example: `new RecursiveSet(1).equals(new RecursiveSet(1))` is `true`.
30
+ - Native `Set` would treat them as distinct objects.
31
+ - **Foundation Axiom:** The library performs cycle detection to prevent sets from containing themselves (recursively).
32
+ - **Performance:** Internally powered by **Functional Red-Black Trees** (via `functional-red-black-tree`).
33
+ - Operations like insertion, deletion, and lookup are **O(log n)**.
34
+ - This allows for stable ordering and efficient deep comparison of nested sets.
35
+
36
+ ---
37
+
24
38
  ## Installation
25
39
 
26
40
  ```
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RecursiveSet = void 0;
7
+ exports.emptySet = emptySet;
8
+ exports.singleton = singleton;
9
+ exports.fromIterable = fromIterable;
10
+ const functional_red_black_tree_1 = __importDefault(require("functional-red-black-tree"));
11
+ /**
12
+ * @module recursive-set
13
+ * A mutable recursive set implementation enforcing Cantor's ZFC axioms
14
+ * Powered by Red-Black Trees for O(log n) operations
15
+ */
16
+ /**
17
+ * Comparator function for ZFC sets
18
+ * Returns -1 if a < b, 1 if a > b, 0 if a == b (structural equality)
19
+ */
20
+ function compare(a, b) {
21
+ // 1. Identity optimization
22
+ if (a === b)
23
+ return 0;
24
+ // 2. Type separation: Sets are "greater" than primitives
25
+ const isSetA = a instanceof RecursiveSet;
26
+ const isSetB = b instanceof RecursiveSet;
27
+ if (isSetA !== isSetB)
28
+ return isSetA ? 1 : -1;
29
+ // 3. Primitives
30
+ if (!isSetA) {
31
+ if (typeof a !== typeof b) {
32
+ return typeof a > typeof b ? 1 : -1;
33
+ }
34
+ return a < b ? -1 : 1;
35
+ }
36
+ // 4. Recursive Sets
37
+ const sizeA = a.size;
38
+ const sizeB = b.size;
39
+ if (sizeA !== sizeB)
40
+ return sizeA < sizeB ? -1 : 1;
41
+ // Lexicographical comparison
42
+ const itA = a[Symbol.iterator]();
43
+ const itB = b[Symbol.iterator]();
44
+ let nextA = itA.next();
45
+ let nextB = itB.next();
46
+ while (!nextA.done) {
47
+ const cmp = compare(nextA.value, nextB.value);
48
+ if (cmp !== 0)
49
+ return cmp;
50
+ nextA = itA.next();
51
+ nextB = itB.next();
52
+ }
53
+ return 0;
54
+ }
55
+ class RecursiveSet {
56
+ // Red-Black Tree (immutable structure, we replace on mutation)
57
+ _tree; // Type from functional-red-black-tree
58
+ constructor(...elements) {
59
+ this._tree = (0, functional_red_black_tree_1.default)(compare);
60
+ for (const el of elements) {
61
+ this.add(el);
62
+ }
63
+ }
64
+ // === Mutable Operations ===
65
+ add(element) {
66
+ if (element instanceof RecursiveSet) {
67
+ if (!this.has(element)) {
68
+ if (this._wouldCreateCycle(element)) {
69
+ throw new Error("Foundation axiom violated: membership cycle detected");
70
+ }
71
+ }
72
+ }
73
+ // Immutable insert - returns new tree
74
+ // We replace our internal tree (mutable API, immutable data structure)
75
+ this._tree = this._tree.insert(element, true);
76
+ return this;
77
+ }
78
+ remove(element) {
79
+ this._tree = this._tree.remove(element);
80
+ return this;
81
+ }
82
+ clear() {
83
+ this._tree = (0, functional_red_black_tree_1.default)(compare);
84
+ return this;
85
+ }
86
+ // === Immutable Operations ===
87
+ union(other) {
88
+ const result = new RecursiveSet();
89
+ for (const el of this)
90
+ result.add(el);
91
+ for (const el of other)
92
+ result.add(el);
93
+ return result;
94
+ }
95
+ intersection(other) {
96
+ const result = new RecursiveSet();
97
+ for (const el of this) {
98
+ if (other.has(el)) {
99
+ result.add(el);
100
+ }
101
+ }
102
+ return result;
103
+ }
104
+ difference(other) {
105
+ const result = new RecursiveSet();
106
+ for (const el of this) {
107
+ if (!other.has(el)) {
108
+ result.add(el);
109
+ }
110
+ }
111
+ return result;
112
+ }
113
+ symmetricDifference(other) {
114
+ return this.union(other).difference(this.intersection(other));
115
+ }
116
+ powerset() {
117
+ const elements = [];
118
+ this._tree.forEach((key) => elements.push(key));
119
+ const subsets = [];
120
+ const n = elements.length;
121
+ for (let i = 0; i < (1 << n); i++) {
122
+ const subset = new RecursiveSet();
123
+ for (let j = 0; j < n; j++) {
124
+ if (i & (1 << j)) {
125
+ subset.add(elements[j]);
126
+ }
127
+ }
128
+ subsets.push(subset);
129
+ }
130
+ return new RecursiveSet(...subsets);
131
+ }
132
+ cartesianProduct(other) {
133
+ const pairs = [];
134
+ for (const x of this) {
135
+ for (const y of other) {
136
+ const valX = x;
137
+ const valY = y;
138
+ const pair = new RecursiveSet(new RecursiveSet(valX), new RecursiveSet(valX, valY));
139
+ pairs.push(pair);
140
+ }
141
+ }
142
+ return new RecursiveSet(...pairs);
143
+ }
144
+ // === Predicates ===
145
+ has(element) {
146
+ return this._tree.get(element) !== undefined;
147
+ }
148
+ isSubset(other) {
149
+ for (const el of this) {
150
+ if (!other.has(el))
151
+ return false;
152
+ }
153
+ return true;
154
+ }
155
+ isSuperset(other) {
156
+ return other.isSubset(this);
157
+ }
158
+ isProperSubset(other) {
159
+ return this.isSubset(other) && !this.equals(other);
160
+ }
161
+ isEmpty() {
162
+ return this.size === 0;
163
+ }
164
+ equals(other) {
165
+ return compare(this, other) === 0;
166
+ }
167
+ // === Internals ===
168
+ _wouldCreateCycle(element) {
169
+ const visited = new Set();
170
+ const stack = [element];
171
+ while (stack.length > 0) {
172
+ const current = stack.pop();
173
+ if (current === this)
174
+ return true;
175
+ if (visited.has(current))
176
+ continue;
177
+ visited.add(current);
178
+ for (const child of current) {
179
+ if (child instanceof RecursiveSet) {
180
+ stack.push(child);
181
+ }
182
+ }
183
+ }
184
+ return false;
185
+ }
186
+ // === Utility ===
187
+ get size() {
188
+ return this._tree.length;
189
+ }
190
+ toSet() {
191
+ const result = new Set();
192
+ this._tree.forEach((key) => result.add(key));
193
+ return result;
194
+ }
195
+ *[Symbol.iterator]() {
196
+ const keys = [];
197
+ this._tree.forEach((key) => keys.push(key));
198
+ yield* keys;
199
+ }
200
+ toString() {
201
+ if (this.isEmpty())
202
+ return "∅";
203
+ const elements = [];
204
+ this._tree.forEach((key) => {
205
+ if (key instanceof RecursiveSet) {
206
+ elements.push(key.toString());
207
+ }
208
+ else {
209
+ elements.push(String(key));
210
+ }
211
+ });
212
+ return `{${elements.join(", ")}}`;
213
+ }
214
+ [Symbol.for('nodejs.util.inspect.custom')]() {
215
+ return this.toString();
216
+ }
217
+ }
218
+ exports.RecursiveSet = RecursiveSet;
219
+ // === Helpers ===
220
+ function emptySet() {
221
+ return new RecursiveSet();
222
+ }
223
+ function singleton(element) {
224
+ return new RecursiveSet(element);
225
+ }
226
+ function fromIterable(iterable) {
227
+ return new RecursiveSet(...iterable);
228
+ }
229
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AA0PA,4BAEC;AAED,8BAEC;AAED,oCAEC;AApQD,0FAAmD;AAEnD;;;;GAIG;AAEH;;;GAGG;AACH,SAAS,OAAO,CAAC,CAAM,EAAE,CAAM;IAC3B,2BAA2B;IAC3B,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAEtB,yDAAyD;IACzD,MAAM,MAAM,GAAG,CAAC,YAAY,YAAY,CAAC;IACzC,MAAM,MAAM,GAAG,CAAC,YAAY,YAAY,CAAC;IACzC,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAA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"
3
+ }
@@ -0,0 +1,28 @@
1
+ export declare class RecursiveSet<T = any> {
2
+ private _tree;
3
+ constructor(...elements: Array<T | RecursiveSet<T>>);
4
+ add(element: T | RecursiveSet<T>): this;
5
+ remove(element: T | RecursiveSet<T>): this;
6
+ clear(): this;
7
+ union(other: RecursiveSet<T>): RecursiveSet<T>;
8
+ intersection(other: RecursiveSet<T>): RecursiveSet<T>;
9
+ difference(other: RecursiveSet<T>): RecursiveSet<T>;
10
+ symmetricDifference(other: RecursiveSet<T>): RecursiveSet<T>;
11
+ powerset(): RecursiveSet<RecursiveSet<T>>;
12
+ cartesianProduct<U>(other: RecursiveSet<U>): RecursiveSet<RecursiveSet<T | U>>;
13
+ has(element: T | RecursiveSet<T>): boolean;
14
+ isSubset(other: RecursiveSet<T>): boolean;
15
+ isSuperset(other: RecursiveSet<T>): boolean;
16
+ isProperSubset(other: RecursiveSet<T>): boolean;
17
+ isEmpty(): boolean;
18
+ equals(other: RecursiveSet<T>): boolean;
19
+ private _wouldCreateCycle;
20
+ get size(): number;
21
+ toSet(): Set<T | RecursiveSet<T>>;
22
+ [Symbol.iterator](): Iterator<T | RecursiveSet<T>>;
23
+ toString(): string;
24
+ }
25
+ export declare function emptySet<T = any>(): RecursiveSet<T>;
26
+ export declare function singleton<T>(element: T): RecursiveSet<T>;
27
+ export declare function fromIterable<T>(iterable: Iterable<T>): RecursiveSet<T>;
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAmDA,qBAAa,YAAY,CAAC,CAAC,GAAG,GAAG;IAE7B,OAAO,CAAC,KAAK,CAAM;gBAEP,GAAG,QAAQ,EAAE,KAAK,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IAUnD,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI;IAevC,MAAM,CAAC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CAAC;IAMnD,QAAQ,IAAI,MAAM;CAgBrB;AAGD,wBAAgB,QAAQ,CAAC,CAAC,GAAG,GAAG,KAAK,YAAY,CAAC,CAAC,CAAC,CAEnD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAExD;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEtE"}
@@ -0,0 +1,219 @@
1
+ import createTree from 'functional-red-black-tree';
2
+ /**
3
+ * @module recursive-set
4
+ * A mutable recursive set implementation enforcing Cantor's ZFC axioms
5
+ * Powered by Red-Black Trees for O(log n) operations
6
+ */
7
+ /**
8
+ * Comparator function for ZFC sets
9
+ * Returns -1 if a < b, 1 if a > b, 0 if a == b (structural equality)
10
+ */
11
+ function compare(a, b) {
12
+ // 1. Identity optimization
13
+ if (a === b)
14
+ return 0;
15
+ // 2. Type separation: Sets are "greater" than primitives
16
+ const isSetA = a instanceof RecursiveSet;
17
+ const isSetB = b instanceof RecursiveSet;
18
+ if (isSetA !== isSetB)
19
+ return isSetA ? 1 : -1;
20
+ // 3. Primitives
21
+ if (!isSetA) {
22
+ if (typeof a !== typeof b) {
23
+ return typeof a > typeof b ? 1 : -1;
24
+ }
25
+ return a < b ? -1 : 1;
26
+ }
27
+ // 4. Recursive Sets
28
+ const sizeA = a.size;
29
+ const sizeB = b.size;
30
+ if (sizeA !== sizeB)
31
+ return sizeA < sizeB ? -1 : 1;
32
+ // Lexicographical comparison
33
+ const itA = a[Symbol.iterator]();
34
+ const itB = b[Symbol.iterator]();
35
+ let nextA = itA.next();
36
+ let nextB = itB.next();
37
+ while (!nextA.done) {
38
+ const cmp = compare(nextA.value, nextB.value);
39
+ if (cmp !== 0)
40
+ return cmp;
41
+ nextA = itA.next();
42
+ nextB = itB.next();
43
+ }
44
+ return 0;
45
+ }
46
+ export class RecursiveSet {
47
+ // Red-Black Tree (immutable structure, we replace on mutation)
48
+ _tree; // Type from functional-red-black-tree
49
+ constructor(...elements) {
50
+ this._tree = createTree(compare);
51
+ for (const el of elements) {
52
+ this.add(el);
53
+ }
54
+ }
55
+ // === Mutable Operations ===
56
+ add(element) {
57
+ if (element instanceof RecursiveSet) {
58
+ if (!this.has(element)) {
59
+ if (this._wouldCreateCycle(element)) {
60
+ throw new Error("Foundation axiom violated: membership cycle detected");
61
+ }
62
+ }
63
+ }
64
+ // Immutable insert - returns new tree
65
+ // We replace our internal tree (mutable API, immutable data structure)
66
+ this._tree = this._tree.insert(element, true);
67
+ return this;
68
+ }
69
+ remove(element) {
70
+ this._tree = this._tree.remove(element);
71
+ return this;
72
+ }
73
+ clear() {
74
+ this._tree = createTree(compare);
75
+ return this;
76
+ }
77
+ // === Immutable Operations ===
78
+ union(other) {
79
+ const result = new RecursiveSet();
80
+ for (const el of this)
81
+ result.add(el);
82
+ for (const el of other)
83
+ result.add(el);
84
+ return result;
85
+ }
86
+ intersection(other) {
87
+ const result = new RecursiveSet();
88
+ for (const el of this) {
89
+ if (other.has(el)) {
90
+ result.add(el);
91
+ }
92
+ }
93
+ return result;
94
+ }
95
+ difference(other) {
96
+ const result = new RecursiveSet();
97
+ for (const el of this) {
98
+ if (!other.has(el)) {
99
+ result.add(el);
100
+ }
101
+ }
102
+ return result;
103
+ }
104
+ symmetricDifference(other) {
105
+ return this.union(other).difference(this.intersection(other));
106
+ }
107
+ powerset() {
108
+ const elements = [];
109
+ this._tree.forEach((key) => elements.push(key));
110
+ const subsets = [];
111
+ const n = elements.length;
112
+ for (let i = 0; i < (1 << n); i++) {
113
+ const subset = new RecursiveSet();
114
+ for (let j = 0; j < n; j++) {
115
+ if (i & (1 << j)) {
116
+ subset.add(elements[j]);
117
+ }
118
+ }
119
+ subsets.push(subset);
120
+ }
121
+ return new RecursiveSet(...subsets);
122
+ }
123
+ cartesianProduct(other) {
124
+ const pairs = [];
125
+ for (const x of this) {
126
+ for (const y of other) {
127
+ const valX = x;
128
+ const valY = y;
129
+ const pair = new RecursiveSet(new RecursiveSet(valX), new RecursiveSet(valX, valY));
130
+ pairs.push(pair);
131
+ }
132
+ }
133
+ return new RecursiveSet(...pairs);
134
+ }
135
+ // === Predicates ===
136
+ has(element) {
137
+ return this._tree.get(element) !== undefined;
138
+ }
139
+ isSubset(other) {
140
+ for (const el of this) {
141
+ if (!other.has(el))
142
+ return false;
143
+ }
144
+ return true;
145
+ }
146
+ isSuperset(other) {
147
+ return other.isSubset(this);
148
+ }
149
+ isProperSubset(other) {
150
+ return this.isSubset(other) && !this.equals(other);
151
+ }
152
+ isEmpty() {
153
+ return this.size === 0;
154
+ }
155
+ equals(other) {
156
+ return compare(this, other) === 0;
157
+ }
158
+ // === Internals ===
159
+ _wouldCreateCycle(element) {
160
+ const visited = new Set();
161
+ const stack = [element];
162
+ while (stack.length > 0) {
163
+ const current = stack.pop();
164
+ if (current === this)
165
+ return true;
166
+ if (visited.has(current))
167
+ continue;
168
+ visited.add(current);
169
+ for (const child of current) {
170
+ if (child instanceof RecursiveSet) {
171
+ stack.push(child);
172
+ }
173
+ }
174
+ }
175
+ return false;
176
+ }
177
+ // === Utility ===
178
+ get size() {
179
+ return this._tree.length;
180
+ }
181
+ toSet() {
182
+ const result = new Set();
183
+ this._tree.forEach((key) => result.add(key));
184
+ return result;
185
+ }
186
+ *[Symbol.iterator]() {
187
+ const keys = [];
188
+ this._tree.forEach((key) => keys.push(key));
189
+ yield* keys;
190
+ }
191
+ toString() {
192
+ if (this.isEmpty())
193
+ return "∅";
194
+ const elements = [];
195
+ this._tree.forEach((key) => {
196
+ if (key instanceof RecursiveSet) {
197
+ elements.push(key.toString());
198
+ }
199
+ else {
200
+ elements.push(String(key));
201
+ }
202
+ });
203
+ return `{${elements.join(", ")}}`;
204
+ }
205
+ [Symbol.for('nodejs.util.inspect.custom')]() {
206
+ return this.toString();
207
+ }
208
+ }
209
+ // === Helpers ===
210
+ export function emptySet() {
211
+ return new RecursiveSet();
212
+ }
213
+ export function singleton(element) {
214
+ return new RecursiveSet(element);
215
+ }
216
+ export function fromIterable(iterable) {
217
+ return new RecursiveSet(...iterable);
218
+ }
219
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,2BAA2B,CAAC;AAEnD;;;;GAIG;AAEH;;;GAGG;AACH,SAAS,OAAO,CAAC,CAAM,EAAE,CAAM;IAC3B,2BAA2B;IAC3B,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAEtB,yDAAyD;IACzD,MAAM,MAAM,GAAG,CAAC,YAAY,YAAY,CAAC;IACzC,MAAM,MAAM,GAAG,CAAC,YAAY,YAAY,CAAC;IACzC,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9C,gBAAgB;IAChB,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,IAAI,OAAO,CAAC,KAAK,OAAO,CAAC,EAAE,CAAC;YACxB,OAAO,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IAED,oBAAoB;IACpB,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC;IACrB,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC;IACrB,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEnD,6BAA6B;IAC7B,MAAM,GAAG,GAAG,CAAC,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,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAC/B,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IACtC,CAAC;IAED,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC3B,CAAC;CACJ;AAED,kBAAkB;AAClB,MAAM,UAAU,QAAQ;IACpB,OAAO,IAAI,YAAY,EAAK,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,SAAS,CAAI,OAAU;IACnC,OAAO,IAAI,YAAY,CAAI,OAAO,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,YAAY,CAAI,QAAqB;IACjD,OAAO,IAAI,YAAY,CAAI,GAAG,QAAQ,CAAC,CAAC;AAC5C,CAAC"}
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "recursive-set",
3
- "version": "1.0.1",
3
+ "version": "2.0.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
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
10
+ "types": "./dist/esm/index.d.ts",
11
+ "import": "./dist/esm/index.js",
12
+ "require": "./dist/cjs/index.js"
12
13
  }
13
14
  },
14
15
  "files": [
@@ -16,9 +17,9 @@
16
17
  ],
17
18
  "scripts": {
18
19
  "prepublishOnly": "npm run build",
19
- "build": "tsc",
20
+ "build": "rimraf dist && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/postbuild.cjs",
20
21
  "watch": "tsc --watch",
21
- "clean": "rm -rf dist",
22
+ "clean": "rimraf dist",
22
23
  "test": "tsx test.ts"
23
24
  },
24
25
  "keywords": [
@@ -42,8 +43,13 @@
42
43
  },
43
44
  "homepage": "https://github.com/cstrerath/recursive-set#readme",
44
45
  "devDependencies": {
46
+ "@types/functional-red-black-tree": "^1.0.6",
45
47
  "@types/node": "^20.0.0",
48
+ "rimraf": "^6.1.2",
46
49
  "tsx": "^4.20.6",
47
50
  "typescript": "^5.6.0"
51
+ },
52
+ "dependencies": {
53
+ "functional-red-black-tree": "^1.0.1"
48
54
  }
49
55
  }
package/dist/index.d.ts DELETED
@@ -1,129 +0,0 @@
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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ursiveSet: 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
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
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,MAAM,OAAO,GAAwB,CAAC,OAAO,CAAC,CAAC;QAE/C,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;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