Skip to content

Commit 6c41c4f

Browse files
BaseExpr -> Expr
1 parent 7c82c4a commit 6c41c4f

16 files changed

+89
-88
lines changed

docs/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ _This project uses semantic versioning. Before 1.0.0, this means that every brea
3232

3333
- Fix bug calling methods on paramterized types (e.g. `Map[i64, i64].empty().insert(i64(0), i64(1))`)
3434
- Fix bug for Unit type (egg name is `Unit` not `unit`)
35-
- Use `@class_` decorator to force subclassing `BaseExpr`
35+
- Use `@class_` decorator to force subclassing `Expr`
3636
- Workaround extracting definitions until [upstream is fixed](https://github.com/egraphs-good/egglog/pull/140)
3737
- Rename `Map.map_remove` to `Map.remove`.
3838
- Add lambda calculus example

docs/explanation/2023_07_presentation.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@
825825
"egraph = EGraph()\n",
826826
"\n",
827827
"@egraph.class_\n",
828-
"class Structure(BaseExpr): ...\n",
828+
"class Structure(Expr): ...\n",
829829
"\n",
830830
"a = egraph.constant('a', Structure)\n",
831831
"b = egraph.constant('b', Structure)\n",
@@ -2118,7 +2118,7 @@
21182118
"egraph = EGraph()\n",
21192119
"\n",
21202120
"@egraph.class_\n",
2121-
"class Num(BaseExpr):\n",
2121+
"class Num(Expr):\n",
21222122
" \n",
21232123
" @classmethod\n",
21242124
" def var(cls, name: StringLike) -> Num: ...\n",
@@ -4172,7 +4172,7 @@
41724172
"outputs": [],
41734173
"source": [
41744174
"@ndarray_mod.class_\n",
4175-
"class Value(BaseExpr):\n",
4175+
"class Value(Expr):\n",
41764176
" def __init__(self, v: i64Like) -> None:\n",
41774177
" ...\n",
41784178
"\n",
@@ -4191,7 +4191,7 @@
41914191
"\n",
41924192
"\n",
41934193
"@ndarray_mod.class_\n",
4194-
"class Values(BaseExpr):\n",
4194+
"class Values(Expr):\n",
41954195
" def __init__(self, v: Vec[Value]) -> None:\n",
41964196
" ...\n",
41974197
"\n",
@@ -4226,7 +4226,7 @@
42264226
"outputs": [],
42274227
"source": [
42284228
"@ndarray_mod.class_\n",
4229-
"class NDArray(BaseExpr):\n",
4229+
"class NDArray(Expr):\n",
42304230
" def __getitem__(self, idx: Values) -> Value: ...\n",
42314231
" def shape(self) -> Values: ...\n",
42324232
"\n",

docs/explanation/compared_to_rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ from egglog import *
107107
egraph = EGraph()
108108
109109
@egraph.class_
110-
class Math(BaseExpr):
110+
class Math(Expr):
111111
def __init__(self, value: i64Like) -> None:
112112
...
113113

docs/explanation/pldi_2023_presentation.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@
597597
"outputs": [],
598598
"source": [
599599
"@ndarray_mod.class_\n",
600-
"class Value(BaseExpr):\n",
600+
"class Value(Expr):\n",
601601
" def __init__(self, v: i64Like) -> None:\n",
602602
" ...\n",
603603
"\n",
@@ -616,7 +616,7 @@
616616
"\n",
617617
"\n",
618618
"@ndarray_mod.class_\n",
619-
"class Values(BaseExpr):\n",
619+
"class Values(Expr):\n",
620620
" def __init__(self, v: Vec[Value]) -> None:\n",
621621
" ...\n",
622622
"\n",
@@ -651,7 +651,7 @@
651651
"outputs": [],
652652
"source": [
653653
"@ndarray_mod.class_\n",
654-
"class NDArray(BaseExpr):\n",
654+
"class NDArray(Expr):\n",
655655
" def __getitem__(self, idx: Values) -> Value: ...\n",
656656
" def shape(self) -> Values: ...\n",
657657
"\n",
@@ -2989,7 +2989,7 @@
29892989
"egraph = EGraph()\n",
29902990
"\n",
29912991
"@egraph.class_\n",
2992-
"class Num(BaseExpr):\n",
2992+
"class Num(Expr):\n",
29932993
" \n",
29942994
" @classmethod\n",
29952995
" def var(cls, name: StringLike) -> Num: ...\n",

docs/reference/egglog-translation.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ The `!=` function in egglog works on any two types with the same sort. In Python
5858
i64(10) != i64(2)
5959
```
6060

61-
This is checked statically, based on the `__ne__` definition in `BaseExpr`, so that only sorts that have the same sort can be compared.
61+
This is checked statically, based on the `__ne__` definition in `Expr`, so that only sorts that have the same sort can be compared.
6262

6363
## Declaring Sorts
6464

65-
Users can declare their own sorts in Python by subclassing the `BaseExpr` class and decorating with `@egraph.class_` to register it with the e-graph:
65+
Users can declare their own sorts in Python by subclassing the `Expr` class and decorating with `@egraph.class_` to register it with the e-graph:
6666

6767
```{code-cell} python
6868
egraph = EGraph()
6969
7070
# egg: (datatype Math)
7171
@egraph.class_
72-
class Math(BaseExpr):
72+
class Math(Expr):
7373
pass
7474
```
7575

@@ -80,7 +80,7 @@ egraph = EGraph()
8080
8181
# egg: (datatype Math2)
8282
@egraph.class_(egg_sort="Math2")
83-
class Math(BaseExpr):
83+
class Math(Expr):
8484
pass
8585
```
8686

@@ -148,7 +148,7 @@ Note that by default, the egg name for any method is the Python class name combi
148148
# (Mul Math Math))
149149
150150
@egraph.class_
151-
class Math(BaseExpr):
151+
class Math(Expr):
152152
@egraph.method(egg_fn="Num")
153153
def __init__(self, v: i64Like):
154154
...

docs/tutorials/array-api.ipynb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@
216216
"\n",
217217
"egraph = EGraph()\n",
218218
"\n",
219-
"T = TypeVar(\"T\", bound=BaseExpr)\n",
219+
"T = TypeVar(\"T\", bound=Expr)\n",
220220
"\n",
221221
"runtime_ruleset = egraph.ruleset(\"runtime\")\n",
222222
"\n",
223-
"def extract_py(e: BaseExpr) -> Any:\n",
223+
"def extract_py(e: Expr) -> Any:\n",
224224
" print(e)\n",
225225
" egraph.register(e)\n",
226226
" egraph.run(run(limit=10).saturate())\n",
@@ -233,7 +233,7 @@
233233
" return res\n",
234234
"\n",
235235
"@egraph.class_\n",
236-
"class Bool(BaseExpr):\n",
236+
"class Bool(Expr):\n",
237237
" @egraph.method(preserve=True)\n",
238238
" def __bool__(self) -> bool:\n",
239239
" return extract_py(self)\n",
@@ -260,7 +260,7 @@
260260
"\n",
261261
"\n",
262262
"@egraph.class_\n",
263-
"class DType(BaseExpr):\n",
263+
"class DType(Expr):\n",
264264
" float64: ClassVar[DType]\n",
265265
" float32: ClassVar[DType]\n",
266266
" int64: ClassVar[DType]\n",
@@ -285,7 +285,7 @@
285285
"\n",
286286
"\n",
287287
"@egraph.class_\n",
288-
"class IsDtypeKind(BaseExpr):\n",
288+
"class IsDtypeKind(Expr):\n",
289289
" NULL: ClassVar[IsDtypeKind]\n",
290290
"\n",
291291
" @classmethod\n",
@@ -343,7 +343,7 @@
343343
"\n",
344344
"\n",
345345
"@egraph.class_\n",
346-
"class Int(BaseExpr):\n",
346+
"class Int(Expr):\n",
347347
" def __init__(self, value: i64Like) -> None:\n",
348348
" ...\n",
349349
"\n",
@@ -417,7 +417,7 @@
417417
"assert expr_parts(egraph.simplify(Int(2) >= Int(1), 10)) == expr_parts(TRUE)\n",
418418
"\n",
419419
"@egraph.class_\n",
420-
"class TupleInt(BaseExpr):\n",
420+
"class TupleInt(Expr):\n",
421421
" EMPTY: ClassVar[TupleInt]\n",
422422
"\n",
423423
" def __init__(self, head: Int) -> None:\n",
@@ -458,7 +458,7 @@
458458
"# HANDLED_FUNCTIONS = {}\n",
459459
"\n",
460460
"@egraph.class_\n",
461-
"class IndexKey(BaseExpr):\n",
461+
"class IndexKey(Expr):\n",
462462
" @classmethod\n",
463463
" def tuple_int(cls, ti: TupleInt) -> IndexKey:\n",
464464
" ...\n",
@@ -472,7 +472,7 @@
472472
"converter(Int, IndexKey, lambda x: IndexKey.int(x))\n",
473473
"\n",
474474
"@egraph.class_\n",
475-
"class NDArray(BaseExpr):\n",
475+
"class NDArray(Expr):\n",
476476
" def __init__(self, py_array: PyObject) -> None:\n",
477477
" ...\n",
478478
"\n",
@@ -539,7 +539,7 @@
539539
"\n",
540540
"\n",
541541
"@egraph.class_\n",
542-
"class OptionalBool(BaseExpr):\n",
542+
"class OptionalBool(Expr):\n",
543543
" none: ClassVar[OptionalBool]\n",
544544
"\n",
545545
" @classmethod\n",
@@ -553,7 +553,7 @@
553553
"\n",
554554
"\n",
555555
"@egraph.class_\n",
556-
"class OptionalDType(BaseExpr):\n",
556+
"class OptionalDType(Expr):\n",
557557
" none: ClassVar[OptionalDType]\n",
558558
"\n",
559559
" @classmethod\n",

docs/tutorials/getting-started.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"outputs": [],
8585
"source": [
8686
"@egraph.class_\n",
87-
"class Dim(BaseExpr):\n",
87+
"class Dim(Expr):\n",
8888
" \"\"\"\n",
8989
" A dimension of a matix.\n",
9090
"\n",
@@ -267,7 +267,7 @@
267267
"outputs": [],
268268
"source": [
269269
"@egraph.class_\n",
270-
"class Matrix(BaseExpr):\n",
270+
"class Matrix(Expr):\n",
271271
" @classmethod\n",
272272
" def identity(cls, dim: Dim) -> Matrix:\n",
273273
" \"\"\"\n",

python/egglog/builtins.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from typing import Generic, TypeVar, Union
99

10-
from .egraph import BUILTINS, BaseExpr, Unit
10+
from .egraph import BUILTINS, Expr, Unit
1111
from .runtime import converter
1212

1313
__all__ = [
@@ -33,7 +33,7 @@
3333

3434

3535
@BUILTINS.class_(egg_sort="i64")
36-
class i64(BaseExpr):
36+
class i64(Expr):
3737
def __init__(self, value: int):
3838
...
3939

@@ -105,7 +105,7 @@ def max(self, other: i64Like) -> i64: # type: ignore[empty-body]
105105

106106

107107
@BUILTINS.class_(egg_sort="f64")
108-
class f64(BaseExpr):
108+
class f64(Expr):
109109
def __init__(self, value: float):
110110
...
111111

@@ -161,7 +161,7 @@ def max(self, other: f64Like) -> f64: # type: ignore[empty-body]
161161

162162

163163
@BUILTINS.class_
164-
class String(BaseExpr):
164+
class String(Expr):
165165
def __init__(self, value: str):
166166
...
167167

@@ -173,12 +173,12 @@ def join(*strings: StringLike) -> String: # type: ignore[empty-body]
173173

174174
converter(str, String, String)
175175

176-
T = TypeVar("T", bound=BaseExpr)
177-
V = TypeVar("V", bound=BaseExpr)
176+
T = TypeVar("T", bound=Expr)
177+
V = TypeVar("V", bound=Expr)
178178

179179

180180
@BUILTINS.class_(egg_sort="Map")
181-
class Map(BaseExpr, Generic[T, V]):
181+
class Map(Expr, Generic[T, V]):
182182
@BUILTINS.method(egg_fn="map-empty")
183183
@classmethod
184184
def empty(cls) -> Map[T, V]: # type: ignore[empty-body]
@@ -206,7 +206,7 @@ def remove(self, key: T) -> Map[T, V]: # type: ignore[empty-body]
206206

207207

208208
@BUILTINS.class_(egg_sort="Set")
209-
class Set(BaseExpr, Generic[T]):
209+
class Set(Expr, Generic[T]):
210210
@BUILTINS.method(egg_fn="set-of")
211211
def __init__(self, *args: T) -> None:
212212
...
@@ -246,7 +246,7 @@ def __and__(self, other: Set[T]) -> Set[T]: # type: ignore[empty-body]
246246

247247

248248
@BUILTINS.class_(egg_sort="Rational")
249-
class Rational(BaseExpr):
249+
class Rational(Expr):
250250
@BUILTINS.method(egg_fn="rational")
251251
def __init__(self, num: i64Like, den: i64Like):
252252
...
@@ -317,7 +317,7 @@ def cbrt(self) -> Rational: # type: ignore[empty-body]
317317

318318

319319
@BUILTINS.class_(egg_sort="Vec")
320-
class Vec(BaseExpr, Generic[T]):
320+
class Vec(Expr, Generic[T]):
321321
@BUILTINS.method(egg_fn="vec-of")
322322
def __init__(self, *args: T) -> None:
323323
...
@@ -357,7 +357,7 @@ def __getitem__(self, index: i64Like) -> T: # type: ignore[empty-body]
357357

358358

359359
@BUILTINS.class_(egg_sort="PyObject")
360-
class PyObject(BaseExpr):
360+
class PyObject(Expr):
361361
@BUILTINS.method(egg_fn="py-object")
362362
def __init__(self, *hashes: i64) -> None:
363363
...
@@ -380,6 +380,7 @@ def dict_update(dict, *keys_and_values: PyObject) -> PyObject: # type: ignore[e
380380
def from_int(cls, i: i64Like) -> PyObject: # type: ignore[empty-body]
381381
...
382382

383+
383384
# TODO: Maybe move to static method if we implement those?
384385
@BUILTINS.function(egg_fn="py-eval")
385386
def py_eval(code: StringLike, locals: PyObject, globals: PyObject) -> PyObject: # type: ignore[empty-body]

0 commit comments

Comments
 (0)