Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 16 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ crate-type = ["cdylib"]
pyo3 = { version = "0.27", features = ["extension-module", "num-bigint", "num-rational"] }
num-bigint = "*"
num-rational = "*"
egglog = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug", default-features = false }
egglog-bridge = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
egglog-core-relations = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
egglog = { path = "../egg-smol", default-features = false }
egglog-bridge = { path = "../egg-smol/egglog-bridge" }
egglog-core-relations = { path = "../egg-smol/core-relations" }
egglog-experimental = { git = "https://github.com/egraphs-good/egglog-experimental", branch = "main", default-features = false }
egglog-ast = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
egglog-reports = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
egglog-ast = { path = "../egg-smol/egglog-ast" }
egglog-reports = { path = "../egg-smol/egglog-reports" }
egraph-serialize = { version = "0.3", features = ["serde", "graphviz"] }
serde_json = "1"
pyo3-log = "*"
Expand All @@ -31,11 +31,17 @@ base64 = "0.22.1"

# Use patched version of egglog in experimental
[patch.'https://github.com/egraphs-good/egglog']
egglog = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
egglog-ast = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
egglog-core-relations = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
egglog-bridge = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
egglog-reports = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
egglog = { path = "../egg-smol" }
egglog-core-relations = { path = "../egg-smol/core-relations" }
egglog-ast = { path = "../egg-smol/egglog-ast" }
egglog-reports = { path = "../egg-smol/egglog-reports" }
egglog-bridge = { path = "../egg-smol/egglog-bridge" }

# egglog = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
# egglog-ast = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
# egglog-core-relations = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
# egglog-bridge = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }
# egglog-reports = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "fix-fn-bug" }

# enable debug symbols for easier profiling
[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pathlib # noqa: INP001
import pathlib
import subprocess

##
Expand Down
54 changes: 54 additions & 0 deletions docs/explanation/2026_01_11_containers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# # Container Primitive Sorts
#
# In egglog, we not only have primitive sorts like `i64`, `f64` and `String`, but also container
# sorts like `Vec`, `Set` and `Map`. Similar to other primitives, they have a number of built-in
# functions that are defined on them. They are implemented in Rust and egglog can also be extended
# with extra user defined functions on these container sorts as well as entirely new sorts.
#
# For example, the vector sort `Vec` represents a variable-length ordered collection of elements.
# It supports indexing, length retrieval, appending elements, and more:

# +
# mypy: disable-error-code="empty-body"

from __future__ import annotations
from typing import TypeAlias
from egglog import *


egraph = EGraph(save_egglog_string=True)
# vectors support indexing
egraph.extract(Vec(i64(0), i64(1), i64(2))[0])

# -

# This is translated into egglog primitives which execute "eagerly", i.e. they don't have to wait for a rule to replace
# their execution with concrete values. This also means they can also execute on concrete values directly, not on
# uninterpreted functions.

print(egraph.as_egglog_string)

# As an example, let's look at implementing polynomial expressions in egglog:


# +
class Num(Expr):
def __init__(self, value: i64Like) -> None: ...
@method(cost=2)
def __add__(self, other: NumLike) -> Num: ...
@method(cost=10)
def __mul__(self, other: NumLike) -> Num: ...

# These will be translated to non-reversed ones
def __radd__(self, other: NumLike) -> Num: ...
def __rmul__(self, other: NumLike) -> Num: ...


NumLike: TypeAlias = Num | StringLike | i64Like
converter(i64, Num, Num)

(x, y, z) = vars_("x y z", Num)
(p := x * (y * x + z) + 100 * z)
# -

# Now let's say we want to find the lowest cost way to compute this by potentially factoring it.
Loading
Loading