You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This has a couple of advantages over the text version. Users now know what types
299
-
of functions are available to them and also it can be statically type checked with MyPy,
300
-
to make sure that the types are correct.
301
-
302
-
However, it is much more verbose than the text version!
303
-
304
92
## High level API
305
93
306
-
So would it be possible to make an API that:
94
+
The high level API builds on this API and is designed to:
307
95
308
96
1. Statically type checks as much as possible with MyPy
309
-
2.Is concise to write
97
+
2.Be concise to write
310
98
3. Feels "pythonic"
311
99
100
+
Here is the same example using the high level API:
101
+
312
102
```{code-cell} python
313
103
from __future__ import annotations
314
104
@@ -351,3 +141,21 @@ egraph.run(10)
351
141
352
142
egraph.check(eq(expr1).to(expr2))
353
143
```
144
+
145
+
### Mapping of low level to high level
146
+
147
+
Here are a number of the low level commands, with how they map to the high levle API:
148
+
149
+
-`(datatype Math ...)` -> `@egraph.class_` on a Python class. Internally, each method and classmethod are registered as functions, not as `Variant`s of the datatype, but the end result is the same.
150
+
-`(set-option enable_proofs 1)` -> Not supported
151
+
-`(declare True Bool)` -> As a class variable `True: Bool` or as a constant `True_ = egraph.constant("True", Bool)`. Internally, we don't actually use the `Constant` command but instead map constants to nullary functions which are immediately evaluated. This is how the `Constant` command is desugared in egg-smol anyways.
152
+
-`(define expr1 ...)` -> `expr1 = egraph.define("expr1", ...)` or just `expr1 = ...` if it doesn't need to be added to the e-graph.
153
+
-`(sort MyMap (Map i64 String))` -> `MyMap = Map[i64, String]`. We can use the normal Python generic typing syntax. Internally, when this is used in a type definition, we would create a new sort with the name `Map__i64__String`.
154
+
-`(function f ...)` -> `@egraph.function` on a Python function with no body.
0 commit comments