Low Level: egglog.bindings#

This modules contains bindings for the rust egglog library which are meant to be as close to the source as possible. This might result in not the most ergonomic API, if so, we can build higher level abstractions on top of it.

Example:

from egglog.bindings import *

eqsat_basic = """(datatype Math
  (Num i64)
  (Var String)
  (Add Math Math)
  (Mul Math Math))

;; expr1 = 2 * (x + 3)
(let expr1 (Mul (Num 2) (Add (Var "x") (Num 3))))
;; expr2 = 6 + 2 * x
(let expr2 (Add (Num 6) (Mul (Num 2) (Var "x"))))


(rewrite (Add a b)
         (Add b a))
(rewrite (Mul a (Add b c))
         (Add (Mul a b) (Mul a c)))
(rewrite (Add (Num a) (Num b))
         (Num (+ a b)))
(rewrite (Mul (Num a) (Num b))
         (Num (* a b)))

(run 10)
(check (= expr1 expr2))"""

egraph = EGraph()
commands = egraph.parse_program(eqsat_basic)
egraph.run_program(*commands)
[]

The commands are a representation which is close the AST of the egglog text language. We can see this by printing the commands:

for command in commands:
    print(command)
(datatype Math (Num i64) (Var String) (Add Math Math) (Mul Math Math))
(let expr1 (Mul (Num 2) (Add (Var "x") (Num 3))))
(let expr2 (Add (Num 6) (Mul (Num 2) (Var "x"))))
(rewrite (Add a b) (Add b a))
(rewrite (Mul a (Add b c)) (Add (Mul a b) (Mul a c)))
(rewrite (Add (Num a) (Num b)) (Num (+ a b)))
(rewrite (Mul (Num a) (Num b)) (Num (* a b)))
(run-schedule (repeat 10 (run)))
(check (= expr1 expr2))

Bindings for egg_smol rust library

class egglog.bindings.ActionCommand(action)#
action#
class egglog.bindings.AddRuleset(name)#
name#
class egglog.bindings.Best(termdag, cost, term)#
cost#
term#
termdag#
class egglog.bindings.BiRewriteCommand(name, rewrite)#
name#
rewrite#
class egglog.bindings.Bool(value)#
value#
class egglog.bindings.Calc(identifiers, exprs)#
exprs#
identifiers#
class egglog.bindings.Call(name, args)#
args#
name#
class egglog.bindings.Change(change, sym, args)#
args#
change#
sym#
class egglog.bindings.Check(facts)#
facts#
class egglog.bindings.CheckProof#
class egglog.bindings.Datatype(name, variants)#
name#
variants#
class egglog.bindings.Declare(name, sort)#
name#
sort#
class egglog.bindings.Delete#
class egglog.bindings.EGraph#

Create an empty EGraph.

commands()#

Returns the text of the commands that have been run so far, if record was passed.

eval_bool(expr, /)#
eval_f64(expr, /)#
eval_i64(expr, /)#
eval_py_object(expr, /)#

Evaluates an expression in the EGraph and returns the result as a Python object.

eval_rational(expr, /)#
eval_string(expr, /)#
extract_report()#

Gets the last expressions extracted from the EGraph, if the last command was a Simplify or Extract command.

parse_program(input, /)#

Parse a program into a list of commands.

run_program(*commands)#

Run a series of commands on the EGraph. Returns a list of strings representing the output. An EggSmolError is raised if there is problem parsing or executing.

run_report()#

Gets the last run report from the EGraph, if the last command was a run or simplify command.

serialize(root_eclasses, *, max_functions=None, max_calls_per_function=None, include_temporary_functions=False, split_primitive_outputs=False)#

Serialize the EGraph to a SerializedEGraph object.

exception egglog.bindings.EggSmolError(context)#
context#
class egglog.bindings.Eq(exprs)#
exprs#
class egglog.bindings.Expr_(expr)#
expr#
class egglog.bindings.Extract(expr, variants)#
expr#
variants#
class egglog.bindings.F64(value)#
value#
class egglog.bindings.Fact(expr)#
expr#
class egglog.bindings.Fail(command)#
command#
class egglog.bindings.Function(decl)#
decl#
class egglog.bindings.FunctionDecl(name, schema, default=Ellipsis, merge=Ellipsis, merge_action=Ellipsis, cost=Ellipsis, unextractable=Ellipsis, ignore_viz=Ellipsis)#
cost#
default#
ignore_viz#
merge#
merge_action#
name#
schema#
unextractable#
class egglog.bindings.IdentSort(ident, sort)#
ident#
sort#
class egglog.bindings.Include(path)#
path#
class egglog.bindings.Input(name, file)#
file#
name#
class egglog.bindings.Int(value)#
value#
class egglog.bindings.Let(lhs, rhs)#
lhs#
rhs#
class egglog.bindings.Lit(value)#
value#
class egglog.bindings.Output(file, exprs)#
exprs#
file#
class egglog.bindings.Panic(msg)#
msg#
class egglog.bindings.Pop(length)#
length#
class egglog.bindings.PrintFunction(name, length)#
length#
name#
class egglog.bindings.PrintOverallStatistics#
class egglog.bindings.PrintSize(name)#
name#
class egglog.bindings.Push(length)#
length#
class egglog.bindings.PyObjectSort#
store(obj, /)#

Store a Python object and return an Expr that points to it.

class egglog.bindings.QueryExtract(variants, expr)#
expr#
variants#
class egglog.bindings.Relation(constructor, inputs)#
constructor#
inputs#
class egglog.bindings.Repeat(length, schedule)#
length#
schedule#
class egglog.bindings.Rewrite(lhs, rhs, conditions=Ellipsis)#
conditions#
lhs#
rhs#
class egglog.bindings.RewriteCommand(name, rewrite, subsume)#
name#
rewrite#
subsume#
class egglog.bindings.Rule(head, body)#
body#
head#
class egglog.bindings.RuleCommand(name, ruleset, rule)#
name#
rule#
ruleset#
class egglog.bindings.Run(config)#
config#
class egglog.bindings.RunConfig(ruleset, until=Ellipsis)#
ruleset#
until#
class egglog.bindings.RunReport(updated, search_time_per_rule, apply_time_per_rule, search_time_per_ruleset, apply_time_per_ruleset, rebuild_time_per_ruleset, num_matches_per_rule)#
apply_time_per_rule#
apply_time_per_ruleset#
num_matches_per_rule#
rebuild_time_per_ruleset#
search_time_per_rule#
search_time_per_ruleset#
updated#
class egglog.bindings.RunSchedule(schedule)#
schedule#
class egglog.bindings.Saturate(schedule)#
schedule#
class egglog.bindings.Schema(input, output)#
input#
output#
class egglog.bindings.Sequence(schedules)#
schedules#
class egglog.bindings.SerializedEGraph#
inline_leaves()#

Inline all leaf nodes into their parents.

map_ops(map)#

Map each op name to a new op name.

saturate_inline_leaves()#

Inline repeatedly until no more changes are made.

to_dot()#

Serialize the egraph to a dot string.

to_json()#

Serialize the egraph to a json string.

class egglog.bindings.Set(lhs, args, rhs)#
args#
lhs#
rhs#
class egglog.bindings.SetOption(name, value)#
name#
value#
class egglog.bindings.Simplify(expr, schedule)#
expr#
schedule#
class egglog.bindings.Sort(name, presort_and_args)#
name#
presort_and_args#
class egglog.bindings.String(value)#
value#
class egglog.bindings.Subsume#
class egglog.bindings.TermApp(name, args)#
args#
name#
class egglog.bindings.TermDag(nodes, hashcons)#
hashcons#
nodes#
class egglog.bindings.TermLit(value)#
value#
class egglog.bindings.TermVar(name)#
name#
class egglog.bindings.Union(lhs, rhs)#
lhs#
rhs#
class egglog.bindings.Unit#
class egglog.bindings.UnstableCombinedRuleset(name, rulesets)#
name#
rulesets#
class egglog.bindings.Var(name)#
name#
class egglog.bindings.Variant(name, types, cost=Ellipsis)#
cost#
name#
types#
class egglog.bindings.Variants(termdag, terms)#
termdag#
terms#
egglog.bindings.termdag_term_to_expr(termdag, term)#