Skip to content

Commit 3993047

Browse files
committed
Update /docs/support-packages/egg.md
1 parent 1f641ea commit 3993047

1 file changed

Lines changed: 43 additions & 8 deletions

File tree

docs/support-packages/egg.md

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ if (eg.find(ax) !== eg.find(bx)) throw new Error("Should be same");
8686

8787
### Congruence Closure
8888

89-
The E-Graph automatically maintains congruence closure. When two E-classes are merged, the `rebuild()` method ensures that all congruent terms remain in the same E-class:
89+
The E-Graph automatically maintains congruence closure. When two E-classes are merged, the `rebuild()` method ensures that all congruent terms remain in the same E-class.
90+
91+
#### Python Example
9092

9193
```python
9294
eg = EGraph()
@@ -110,6 +112,33 @@ assert eg.find(fa) == eg.find(fb)
110112
assert eg.find(gfa) == eg.find(gfb)
111113
```
112114

115+
#### TypeScript Example
116+
117+
```typescript
118+
import { Term } from "atsds";
119+
import { EGraph } from "atsds-egg";
120+
121+
const eg = new EGraph();
122+
123+
// Add terms with nested structure
124+
const fa = eg.add(new Term("(f a)"));
125+
const fb = eg.add(new Term("(f b)"));
126+
const gfa = eg.add(new Term("(g (f a))"));
127+
const gfb = eg.add(new Term("(g (f b))"));
128+
129+
// Merge a and b
130+
const a = eg.add(new Term("a"));
131+
const b = eg.add(new Term("b"));
132+
eg.merge(a, b);
133+
134+
// Rebuild propagates equivalence
135+
eg.rebuild();
136+
137+
// Now all derived terms are equivalent
138+
if (eg.find(fa) !== eg.find(fb)) throw new Error("fa != fb");
139+
if (eg.find(gfa) !== eg.find(gfb)) throw new Error("gfa != gfb");
140+
```
141+
113142
## Core Concepts
114143

115144
### E-Graph Structure
@@ -144,15 +173,21 @@ The hash-consing mechanism ensures that identical E-Nodes share the same E-class
144173

145174
## API Reference
146175

147-
### EGraph
148-
149-
Main class for E-Graph operations:
176+
### Python (apyds-egg)
150177

151-
- `__init__()`: Create a new empty E-Graph
152-
- `add(term: apyds.Term) -> EClassId`: Add a term and return its E-class ID
178+
- `EGraph()`: Create a new E-Graph
179+
- `add(term: apyds.Term) -> EClassId`: Add a term to the E-Graph
153180
- `merge(a: EClassId, b: EClassId) -> EClassId`: Merge two E-classes
154-
- `rebuild() -> None`: Restore congruence closure by processing the worklist
155-
- `find(eclass: EClassId) -> EClassId`: Find the canonical E-class representative
181+
- `rebuild() -> None`: Restore congruence closure
182+
- `find(eclass: EClassId) -> EClassId`: Find canonical E-class representative
183+
184+
### TypeScript (atsds-egg)
185+
186+
- `new EGraph()`: Create a new E-Graph
187+
- `add(term: atsds.Term): EClassId`: Add a term to the E-Graph
188+
- `merge(a: EClassId, b: EClassId): EClassId`: Merge two E-classes
189+
- `rebuild(): void`: Restore congruence closure
190+
- `find(eclass: EClassId): EClassId`: Find canonical E-class representative
156191

157192
## Package Information
158193

0 commit comments

Comments
 (0)