srtree-2.0.0.0: A general library to work with Symbolic Regression expression trees.
Copyright(c) Fabricio Olivetti 2021 - 2024
LicenseBSD3
Maintainerfabricio.olivetti@gmail.com
Stabilityexperimental
Portability
Safe HaskellSafe-Inferred
LanguageHaskell2010

Algorithm.EqSat.Build

Description

Functions related to building and maintaining e-graphs Heavily based on hegg (https:/github.comalt-romes/hegg by alt-romes)

Synopsis

Documentation

add :: Monad m => CostFun -> ENode -> EGraphST m EClassId Source #

adds a new or existing e-node (merging if necessary)

rebuild :: Monad m => CostFun -> EGraphST m () Source #

rebuilds the e-graph after inserting or merging e-classes

repair :: Monad m => CostFun -> EClassId -> ENode -> EGraphST m () Source #

repairs e-node by canonizing its children if the canonized e-node already exists in e-graph, merge the e-classes

repairAnalysis :: Monad m => CostFun -> EClassId -> ENode -> EGraphST m () Source #

repair the analysis of the e-class considering the new added e-node

merge :: Monad m => CostFun -> EClassId -> EClassId -> EGraphST m EClassId Source #

merge to equivalent e-classes

modifyEClass :: Monad m => CostFun -> EClassId -> EGraphST m EClassId Source #

modify an e-class, e.g., add constant e-node and prune non-leaves

DB

createDB :: Monad m => EGraphST m DB Source #

createDB creates a database of patterns from an e-graph it simply calls addToDB for every pair (e-node, e-class id) from the e-graph.

addToDB :: Monad m => ENode -> EClassId -> EGraphST m () Source #

addToDB adds an e-node and e-class id to the database

populate :: Maybe IntTrie -> [EClassId] -> Maybe IntTrie Source #

Populates an IntTrie with a sequence of e-class ids

classOfENode :: Monad m => CostFun -> Map ClassOrVar ClassOrVar -> Pattern -> EGraphST m (Maybe EClassId) Source #

gets the e-node of the target of the rule TODO: add consts and modify

reprPrat :: Monad m => CostFun -> Map ClassOrVar ClassOrVar -> Pattern -> EGraphST m EClassId Source #

adds the target of the rule into the e-graph

isValidConditions :: Monad m => Condition -> (Map ClassOrVar ClassOrVar, ClassOrVar) -> EGraphST m Bool Source #

returns True if the condition of a rule is valid for that match

Tree to e-graph conversion and utility functions

fromTree :: Monad m => CostFun -> Fix SRTree -> EGraphST m EClassId Source #

Creates an e-graph from an expression tree

fromTrees :: Monad m => CostFun -> [Fix SRTree] -> EGraphST m [EClassId] Source #

Builds an e-graph from multiple independent trees

getBest :: Monad m => EClassId -> EGraphST m (Fix SRTree) Source #

gets the best expression given the default cost function

getExpressionFrom :: Monad m => EClassId -> EGraphST m (Fix SRTree) Source #

returns one expression rooted at e-class eId TODO: avoid loopings

getAllExpressionsFrom :: Monad m => EClassId -> EGraphST m [Fix SRTree] Source #

returns all expressions rooted at e-class eId TODO: check for infinite list

getRndExpressionFrom :: EClassId -> EGraphST (State StdGen) (Fix SRTree) Source #

returns a random expression rooted at e-class eId

forceState :: Monad m => StateT s m () Source #