Copyright | (c) Fabricio Olivetti 2021 - 2024 |
---|---|
License | BSD3 |
Maintainer | fabricio.olivetti@gmail.com |
Stability | experimental |
Portability | |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Pattern matching and rule application functions Heavily based on hegg (https:/github.comalt-romes/hegg by alt-romes)
Synopsis
- type DB = Map (SRTree ()) IntTrie
- data IntTrie = IntTrie {}
- data Pattern
- data Rule
- type Query = [Atom]
- type Condition = Map ClassOrVar ClassOrVar -> EGraph -> Bool
- type ClassOrVar = Either EClassId Int
- data Atom = Atom ClassOrVar (SRTree ClassOrVar)
- unFixPat :: Pattern -> SRTree Pattern
- createDB :: EGraph -> DB
- addToDB :: ENode -> EClassId -> State DB ()
- trie :: EClassId -> IntMap IntTrie -> IntTrie
- populate :: Maybe IntTrie -> [EClassId] -> Maybe IntTrie
- canonizeMap :: (Map ClassOrVar ClassOrVar, ClassOrVar) -> EGraphST (Map ClassOrVar ClassOrVar, ClassOrVar)
- applyMatch :: CostFun -> Rule -> (Map ClassOrVar ClassOrVar, ClassOrVar) -> EGraphST ()
- applyMergeOnlyMatch :: CostFun -> Rule -> (Map ClassOrVar ClassOrVar, ClassOrVar) -> EGraphST ()
- target :: Rule -> Pattern
- source :: Rule -> Pattern
- getConditions :: Rule -> [Condition]
- classOfENode :: CostFun -> Map ClassOrVar ClassOrVar -> Pattern -> EGraphST (Maybe EClassId)
- isConst :: EClassId -> EGraphST Bool
- reprPrat :: CostFun -> Map ClassOrVar ClassOrVar -> Pattern -> EGraphST EClassId
- isValidHeight :: (Map ClassOrVar ClassOrVar, ClassOrVar) -> EGraph -> Bool
- isValidConditions :: Condition -> (Map ClassOrVar ClassOrVar, ClassOrVar) -> EGraph -> Bool
- match :: DB -> Pattern -> [(Map ClassOrVar ClassOrVar, ClassOrVar)]
- compileToQuery :: Pattern -> (Query, ClassOrVar)
- getInt :: ClassOrVar -> Int
- getElems :: SRTree a -> [a]
- genericJoin :: DB -> Query -> [Map ClassOrVar ClassOrVar]
- domainX :: DB -> ClassOrVar -> Query -> [ClassOrVar]
- intersectAtoms :: ClassOrVar -> DB -> Query -> [EClassId]
- intersectTries :: ClassOrVar -> Map ClassOrVar EClassId -> IntTrie -> [ClassOrVar] -> Maybe (Set EClassId)
- updateVar :: ClassOrVar -> ClassOrVar -> Query -> Query
- isDiffFrom :: Int -> ClassOrVar -> Bool
- elemOfAtom :: ClassOrVar -> Atom -> Bool
- orderedVars :: Query -> [ClassOrVar]
Documentation
Instances
IsString Pattern # | |
Defined in Algorithm.EqSat.EqSatDB fromString :: String -> Pattern # | |
Floating Pattern # | |
Num Pattern # | |
Fractional Pattern # | |
Show Pattern # | |
type Condition = Map ClassOrVar ClassOrVar -> EGraph -> Bool #
type ClassOrVar = Either EClassId Int #
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.
populate :: Maybe IntTrie -> [EClassId] -> Maybe IntTrie #
Populates an IntTrie with a sequence of e-class ids
canonizeMap :: (Map ClassOrVar ClassOrVar, ClassOrVar) -> EGraphST (Map ClassOrVar ClassOrVar, ClassOrVar) #
applyMatch :: CostFun -> Rule -> (Map ClassOrVar ClassOrVar, ClassOrVar) -> EGraphST () #
applyMergeOnlyMatch :: CostFun -> Rule -> (Map ClassOrVar ClassOrVar, ClassOrVar) -> EGraphST () #
getConditions :: Rule -> [Condition] #
classOfENode :: CostFun -> Map ClassOrVar ClassOrVar -> Pattern -> EGraphST (Maybe EClassId) #
gets the e-node of the target of the rule TODO: add consts and modify
reprPrat :: CostFun -> Map ClassOrVar ClassOrVar -> Pattern -> EGraphST EClassId #
adds the target of the rule into the e-graph
isValidHeight :: (Map ClassOrVar ClassOrVar, ClassOrVar) -> EGraph -> Bool #
isValidConditions :: Condition -> (Map ClassOrVar ClassOrVar, ClassOrVar) -> EGraph -> Bool #
returns True
if the condition of a rule is valid for that match
match :: DB -> Pattern -> [(Map ClassOrVar ClassOrVar, ClassOrVar)] #
Returns the substitution rules
for every match of the pattern source
inside the e-graph.
compileToQuery :: Pattern -> (Query, ClassOrVar) #
Returns a Query (list of atoms) of a pattern
getInt :: ClassOrVar -> Int #
genericJoin :: DB -> Query -> [Map ClassOrVar ClassOrVar] #
Creates the substituion map for the pattern variables for each one of the matched subgraph
domainX :: DB -> ClassOrVar -> Query -> [ClassOrVar] #
returns the e-class id for a certain variable that matches the pattern described by the atoms
intersectAtoms :: ClassOrVar -> DB -> Query -> [EClassId] #
returns all e-class id that can matches this sequence of atoms
intersectTries :: ClassOrVar -> Map ClassOrVar EClassId -> IntTrie -> [ClassOrVar] -> Maybe (Set EClassId) #
searches for the intersection of e-class ids that matches each part of the query. Returns Nothing if the intersection is empty.
var is the current variable being investigated xs is the map of ids being investigated and their corresponding e-class id trie is the current trie of the pattern (i:ids) sequence of root : children of the atom to investigate
updateVar :: ClassOrVar -> ClassOrVar -> Query -> Query #
updates all occurrence of var with the new id x
isDiffFrom :: Int -> ClassOrVar -> Bool #
checks whether two ClassOrVar are different only check if it is a pattern variable, else returns true
elemOfAtom :: ClassOrVar -> Atom -> Bool #
checks if v is an element of an atom
orderedVars :: Query -> [ClassOrVar] #
sorts the variables in a query by the most frequently occurring