atsds-egg 0.0.11 → 0.0.12-alpha1

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 (2) hide show
  1. package/README.md +92 -6
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -10,8 +10,6 @@ This package implements the egg-style E-Graph data structure with deferred congr
10
10
  - **Union-Find**: Path-compressed union-find for disjoint set management
11
11
  - **Congruence Closure**: Automatic maintenance of congruence relationships
12
12
  - **Deferred Rebuilding**: egg-style deferred rebuilding for performance
13
- - **Python Integration**: Seamless integration with apyds terms
14
- - **Type-Safe**: Full type hints for Python 3.11+
15
13
 
16
14
  ## Installation
17
15
 
@@ -23,6 +21,12 @@ pip install apyds-egg
23
21
 
24
22
  Requires Python 3.11-3.14.
25
23
 
24
+ ### TypeScript/JavaScript (npm)
25
+
26
+ ```bash
27
+ npm install atsds-egg
28
+ ```
29
+
26
30
  ## Quick Start
27
31
 
28
32
  ### Python Example
@@ -56,6 +60,37 @@ eg.rebuild()
56
60
  assert eg.find(ax) == eg.find(bx)
57
61
  ```
58
62
 
63
+ ### TypeScript Example
64
+
65
+ ```typescript
66
+ import { Term } from "atsds";
67
+ import { EGraph } from "atsds-egg";
68
+
69
+ // Create an E-Graph
70
+ const eg = new EGraph();
71
+
72
+ // Add terms to the E-Graph
73
+ const a = eg.add(new Term("a"));
74
+ const b = eg.add(new Term("b"));
75
+ const x = eg.add(new Term("x"));
76
+
77
+ // Add compound terms
78
+ const ax = eg.add(new Term("(+ a x)"));
79
+ const bx = eg.add(new Term("(+ b x)"));
80
+
81
+ // Initially, (+ a x) and (+ b x) are in different E-classes
82
+ if (eg.find(ax) === eg.find(bx)) throw new Error("Should be different");
83
+
84
+ // Merge a and b
85
+ eg.merge(a, b);
86
+
87
+ // Rebuild to restore congruence
88
+ eg.rebuild();
89
+
90
+ // Now (+ a x) and (+ b x) are in the same E-class
91
+ if (eg.find(ax) !== eg.find(bx)) throw new Error("Should be same");
92
+ ```
93
+
59
94
  ## Core Concepts
60
95
 
61
96
  ### E-Graph
@@ -69,7 +104,9 @@ An E-Graph is a data structure that efficiently represents and maintains equival
69
104
 
70
105
  ### Congruence Closure
71
106
 
72
- The E-Graph maintains congruence closure automatically. When two E-classes are merged, the E-Graph rebuilds to ensure that congruent terms remain in the same E-class:
107
+ The E-Graph maintains congruence closure automatically. When two E-classes are merged, the E-Graph rebuilds to ensure that congruent terms remain in the same E-class.
108
+
109
+ #### Python Example
73
110
 
74
111
  ```python
75
112
  eg = EGraph()
@@ -90,22 +127,55 @@ eg.rebuild()
90
127
  assert eg.find(fa) == eg.find(fb)
91
128
  ```
92
129
 
130
+ #### TypeScript Example
131
+
132
+ ```typescript
133
+ import { Term } from "atsds";
134
+ import { EGraph } from "atsds-egg";
135
+
136
+ const eg = new EGraph();
137
+
138
+ // Add terms
139
+ const fa = eg.add(new Term("(f a)"));
140
+ const fb = eg.add(new Term("(f b)"));
141
+
142
+ // Merge a and b
143
+ const a = eg.add(new Term("a"));
144
+ const b = eg.add(new Term("b"));
145
+ eg.merge(a, b);
146
+
147
+ // Rebuild maintains congruence
148
+ eg.rebuild();
149
+
150
+ // Now (f a) and (f b) are equivalent
151
+ if (eg.find(fa) !== eg.find(fb)) throw new Error("Congruence failed");
152
+ ```
153
+
93
154
  ## API Overview
94
155
 
95
- ### EGraph
156
+ ### Python (apyds-egg)
96
157
 
97
- - `__init__()`: Create a new E-Graph
158
+ - `EGraph()`: Create a new E-Graph
98
159
  - `add(term: apyds.Term) -> EClassId`: Add a term to the E-Graph
99
160
  - `merge(a: EClassId, b: EClassId) -> EClassId`: Merge two E-classes
100
161
  - `rebuild() -> None`: Restore congruence closure
101
162
  - `find(eclass: EClassId) -> EClassId`: Find canonical E-class representative
102
163
 
164
+ ### TypeScript (atsds-egg)
165
+
166
+ - `new EGraph()`: Create a new E-Graph
167
+ - `add(term: atsds.Term): EClassId`: Add a term to the E-Graph
168
+ - `merge(a: EClassId, b: EClassId): EClassId`: Merge two E-classes
169
+ - `rebuild(): void`: Restore congruence closure
170
+ - `find(eclass: EClassId): EClassId`: Find canonical E-class representative
171
+
103
172
  ## Building from Source
104
173
 
105
174
  ### Prerequisites
106
175
 
107
176
  - Python 3.11-3.14
108
- - apyds package
177
+ - Node.js and npm
178
+ - apyds and atsds packages
109
179
 
110
180
  ### Python Package
111
181
 
@@ -125,6 +195,21 @@ uv run pytest
125
195
  uv run pytest --cov
126
196
  ```
127
197
 
198
+ ### TypeScript Package
199
+
200
+ ```bash
201
+ cd egg
202
+
203
+ # Install dependencies
204
+ npm install
205
+
206
+ # Build package
207
+ npm run build
208
+
209
+ # Run tests
210
+ npm test
211
+ ```
212
+
128
213
  ## License
129
214
 
130
215
  This project is licensed under the GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later).
@@ -133,6 +218,7 @@ This project is licensed under the GNU Affero General Public License v3.0 or lat
133
218
 
134
219
  - **GitHub**: [USTC-KnowledgeComputingLab/ds](https://github.com/USTC-KnowledgeComputingLab/ds) (in `/egg` directory)
135
220
  - **Python Package**: [apyds-egg](https://pypi.org/project/apyds-egg/)
221
+ - **npm Package**: [atsds-egg](https://www.npmjs.com/package/atsds-egg)
136
222
 
137
223
  ## Author
138
224
 
package/package.json CHANGED
@@ -39,5 +39,5 @@
39
39
  "tslib": "^2.8.1",
40
40
  "typescript": "^5.9.3"
41
41
  },
42
- "version": "0.0.11"
42
+ "version": "0.0.12-alpha1"
43
43
  }