Skip to content

Commit 7537084

Browse files
Add docs for include
1 parent 73f528f commit 7537084

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

docs/reference/egglog-translation.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ path_ruleset = egraph.ruleset("path")
311311
# (rule ((edge x y))
312312
# ((path x y)) :ruleset path)
313313
x, y = vars_("x y", i64)
314-
x, y = vars_("x y", i64)
315314
egraph.register(rule(edge(x, y), ruleset=path_ruleset).then(path(x, y)))
316315
```
317316

@@ -500,3 +499,48 @@ with egraph:
500499
egraph.check(eq(Math(0)).to(Math(1)))
501500
egraph.check_fail(eq(Math(0)).to(Math(1)))
502501
```
502+
503+
## Include
504+
505+
The `(include <path>)` command is used to add modularity, by allowing you to pull in the source from another egglog file into the current file.
506+
507+
In Python, we support the same use case with the ability to define a `Module` which is then depended on in `EGraph`. All commands registered on a `Module` won't be run immediately on an `EGraph`, but instead stored so that when they are included, they will be run:
508+
509+
```{code-cell} python
510+
# egg file: path.egg
511+
# (relation path (i64 i64))
512+
# (relation edge (i64 i64))
513+
#
514+
# (rule ((edge x y))
515+
# ((path x y)))
516+
#
517+
# (rule ((path x y) (edge y z))
518+
# ((path x z)))
519+
#
520+
# egg:
521+
# (include "path.egg")
522+
# (edge 1 2)
523+
# (edge 2 3)
524+
# (edge 3 4)
525+
# (run 3)
526+
# (check (path 1 3))
527+
528+
path_mod = Module()
529+
path = path_mod.relation("path", i64, i64)
530+
edge = path_mod.relation("edge", i64, i64)
531+
532+
x, y, z = vars_("x y z", i64)
533+
path_mod.register(
534+
rule(edge(x, y)).then(path(x, y)),
535+
rule(path(x, y), edge(y, z)).then(path(x, z)),
536+
)
537+
538+
egraph = EGraph([path_mod])
539+
egraph.register(
540+
edge(1, 2),
541+
edge(2, 3),
542+
edge(3, 4)
543+
)
544+
egraph.run(3)
545+
egraph.check(path(1, 3))
546+
```

0 commit comments

Comments
 (0)