Skip to content

Commit

Permalink
add symbolic eval egg experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
oflatt committed Jan 31, 2024
1 parent cfa2608 commit a2bacff
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tree_optimizer/src/symbolic-eval.egg
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

;; SymbolicEval tries to
;; The first expr is the term we wish to symbolicly evaluate
;; The second expr is the symbolic arguments (e.g (All (Parallel) (Pair (Get (Arg shared 0) (Get (Arg shared 1))))))
(function SymbolicEval (Expr Expr) Expr :unextractable)
;; symbolic evaluation of a sequence of exprs
(function SymbolicEvalSeq (ListExpr Expr) ListExpr :unextractable)

(ruleset symbolic-eval)

(rewrite (SymbolicEval (Arg shared) vals) vals :ruleset symbolic-evals)
(rewrite (SymbolicEval (Num shared n) vals) (Num shared n) :ruleset symbolic-evals)
(rewrite (SymbolicEval (Boolean shared b) vals) (Boolean shared b) :ruleset symbolic-evals)

(rewrite (SymbolicEvalSeq (Nil) vals) (Nil) :ruleset symbolic-evals)
(rewrite (SymbolicEvalSeq (Cons first rest) vals)
(Cons (SymbolicEval first vals) (SymbolicEvalSeq rest vals))
:ruleset symbolic-evals)

;; demand the inputs are evaluated
(rule ((= lhs (SymbolicEval term vals))
(= term (Let inputs body)))
((union lhs
(SymbolicEval body (SymbolicEval inputs vals))))
:ruleset symbolic-eval)

(rewrite (SymbolicEval (All (Sequential) list) vals)
(All (Sequential) (SymbolicEvalSeq list vals))
:ruleset symbolic-eval)

(let mylet
(Let shared
(All (Parallel) (Pair (Get (Arg shared) 0) (Get (Arg shared) 1)))
(Pair (Get (Arg shared) 1)
(Get (Arg shared) 0))))

(let symboliceval (SymbolicEval mylet (All (Parallel) (Pair (Get (Arg shared) 0) (Get (Arg shared) 1)))))

(run-schedule (saturate symbolic-eval))

(check (= symboliceval
(All (Parallel) (Pair (Get (Arg shared) 0) (Get (Arg shared) 1)))))
1 change: 1 addition & 0 deletions tree_optimizer/src/symbolic-eval.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit a2bacff

Please sign in to comment.