Copyright | (c) Fabricio Olivetti 2021 - 2024 |
---|---|
License | BSD3 |
Maintainer | fabricio.olivetti@gmail.com |
Stability | experimental |
Portability | |
Safe Haskell | None |
Language | Haskell2010 |
Algorithm.EqSat.Egraph
Description
Equality Graph data structure Heavily based on hegg (https:/github.comalt-romes/hegg by alt-romes)
Synopsis
- type EClassId = Int
- type ClassIdMap = IntMap
- type ENode = SRTree EClassId
- type ENodeEnc = (Int, Int, Int, Double)
- type EGraphST (m :: Type -> Type) a = StateT EGraph m a
- type Cost = Int
- type CostFun = SRTree Cost -> Cost
- type RangeTree a = Seq (a, EClassId)
- encodeEnode :: ENode -> ENodeEnc
- decodeEnode :: ENodeEnc -> ENode
- insertRange :: (Ord a, Show a) => EClassId -> a -> RangeTree a -> RangeTree a
- removeRange :: (Ord a, Show a) => EClassId -> a -> RangeTree a -> RangeTree a
- getWithinRange :: Ord a => a -> a -> RangeTree a -> [EClassId]
- getSmallest :: Ord a => RangeTree a -> (a, EClassId)
- getGreatest :: Ord a => RangeTree a -> (a, EClassId)
- data EGraph = EGraph {}
- data EGraphDB = EDB {
- _worklist :: HashSet (EClassId, ENode)
- _analysis :: HashSet (EClassId, ENode)
- _refits :: HashSet EClassId
- _patDB :: DB
- _fitRangeDB :: RangeTree Double
- _dlRangeDB :: RangeTree Double
- _sizeDB :: IntMap IntSet
- _sizeFitDB :: IntMap (RangeTree Double)
- _sizeDLDB :: IntMap (RangeTree Double)
- _unevaluated :: IntSet
- _nextId :: Int
- data EClass = EClass {}
- data Consts
- data Property
- data EClassData = EData {}
- type DB = Map (SRTree ()) IntTrie
- data IntTrie = IntTrie {}
- canonicalMap :: Lens' EGraph (ClassIdMap EClassId)
- eClass :: Lens' EGraph (ClassIdMap EClass)
- eDB :: Lens' EGraph EGraphDB
- eNodeToEClass :: Lens' EGraph (Map ENode EClassId)
- eClassId :: Lens' EClass Int
- eNodes :: Lens' EClass (HashSet ENodeEnc)
- height :: Lens' EClass Int
- info :: Lens' EClass EClassData
- parents :: Lens' EClass (HashSet (EClassId, ENode))
- best :: Lens' EClassData ENode
- consts :: Lens' EClassData Consts
- cost :: Lens' EClassData Cost
- dl :: Lens' EClassData (Maybe Double)
- fitness :: Lens' EClassData (Maybe Double)
- size :: Lens' EClassData Int
- theta :: Lens' EClassData (Maybe PVector)
- analysis :: Lens' EGraphDB (HashSet (EClassId, ENode))
- dlRangeDB :: Lens' EGraphDB (RangeTree Double)
- fitRangeDB :: Lens' EGraphDB (RangeTree Double)
- nextId :: Lens' EGraphDB Int
- patDB :: Lens' EGraphDB DB
- refits :: Lens' EGraphDB (HashSet EClassId)
- sizeDB :: Lens' EGraphDB (IntMap IntSet)
- sizeDLDB :: Lens' EGraphDB (IntMap (RangeTree Double))
- sizeFitDB :: Lens' EGraphDB (IntMap (RangeTree Double))
- unevaluated :: Lens' EGraphDB IntSet
- worklist :: Lens' EGraphDB (HashSet (EClassId, ENode))
- emptyGraph :: EGraph
- emptyDB :: EGraphDB
- createEClass :: EClassId -> ENode -> EClassData -> Int -> EClass
- canonical :: forall (m :: Type -> Type). Monad m => EClassId -> EGraphST m EClassId
- canonize :: forall (m :: Type -> Type). Monad m => ENode -> EGraphST m ENode
- getEClass :: forall (m :: Type -> Type). Monad m => EClassId -> EGraphST m EClass
- trie :: EClassId -> IntMap IntTrie -> IntTrie
- isConst :: forall (m :: Type -> Type). Monad m => EClassId -> EGraphST m Bool
Documentation
type ClassIdMap = IntMap Source #
encodeEnode :: ENode -> ENodeEnc Source #
this assumes up to 999 variables and params
decodeEnode :: ENodeEnc -> ENode Source #
Constructors
EGraph | |
Fields |
Instances
Constructors
EDB | |
Fields
|
Instances
Binary EGraphDB Source # | |||||
Generic EGraphDB Source # | |||||
Defined in Algorithm.EqSat.Egraph Associated Types
| |||||
Show EGraphDB Source # | |||||
type Rep EGraphDB Source # | |||||
Defined in Algorithm.EqSat.Egraph type Rep EGraphDB = D1 ('MetaData "EGraphDB" "Algorithm.EqSat.Egraph" "srtree-2.0.0.4-inplace" 'False) (C1 ('MetaCons "EDB" 'PrefixI 'True) (((S1 ('MetaSel ('Just "_worklist") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (HashSet (EClassId, ENode))) :*: S1 ('MetaSel ('Just "_analysis") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (HashSet (EClassId, ENode)))) :*: (S1 ('MetaSel ('Just "_refits") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (HashSet EClassId)) :*: (S1 ('MetaSel ('Just "_patDB") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 DB) :*: S1 ('MetaSel ('Just "_fitRangeDB") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (RangeTree Double))))) :*: ((S1 ('MetaSel ('Just "_dlRangeDB") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (RangeTree Double)) :*: (S1 ('MetaSel ('Just "_sizeDB") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (IntMap IntSet)) :*: S1 ('MetaSel ('Just "_sizeFitDB") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (IntMap (RangeTree Double))))) :*: (S1 ('MetaSel ('Just "_sizeDLDB") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (IntMap (RangeTree Double))) :*: (S1 ('MetaSel ('Just "_unevaluated") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 IntSet) :*: S1 ('MetaSel ('Just "_nextId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)))))) |
Constructors
EClass | |
Instances
Binary EClass Source # | |||||
Generic EClass Source # | |||||
Defined in Algorithm.EqSat.Egraph Associated Types
| |||||
Show EClass Source # | |||||
Eq EClass Source # | |||||
type Rep EClass Source # | |||||
Defined in Algorithm.EqSat.Egraph type Rep EClass = D1 ('MetaData "EClass" "Algorithm.EqSat.Egraph" "srtree-2.0.0.4-inplace" 'False) (C1 ('MetaCons "EClass" 'PrefixI 'True) ((S1 ('MetaSel ('Just "_eClassId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "_eNodes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (HashSet ENodeEnc))) :*: (S1 ('MetaSel ('Just "_parents") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (HashSet (EClassId, ENode))) :*: (S1 ('MetaSel ('Just "_height") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "_info") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 EClassData))))) |
Instances
Binary Consts Source # | |||||
Generic Consts Source # | |||||
Defined in Algorithm.EqSat.Egraph Associated Types
| |||||
Show Consts Source # | |||||
Eq Consts Source # | |||||
type Rep Consts Source # | |||||
Defined in Algorithm.EqSat.Egraph type Rep Consts = D1 ('MetaData "Consts" "Algorithm.EqSat.Egraph" "srtree-2.0.0.4-inplace" 'False) (C1 ('MetaCons "NotConst" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "ParamIx" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "ConstVal" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Double)))) |
Instances
Binary Property Source # | |||||
Generic Property Source # | |||||
Defined in Algorithm.EqSat.Egraph Associated Types
| |||||
Show Property Source # | |||||
Eq Property Source # | |||||
type Rep Property Source # | |||||
Defined in Algorithm.EqSat.Egraph type Rep Property = D1 ('MetaData "Property" "Algorithm.EqSat.Egraph" "srtree-2.0.0.4-inplace" 'False) ((C1 ('MetaCons "Positive" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Negative" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "NonZero" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Real" 'PrefixI 'False) (U1 :: Type -> Type))) |
data EClassData Source #
Constructors
EData | |
Instances
Binary EClassData Source # | |||||
Defined in Algorithm.EqSat.Egraph | |||||
Generic EClassData Source # | |||||
Defined in Algorithm.EqSat.Egraph Associated Types
| |||||
Show EClassData Source # | |||||
Defined in Algorithm.EqSat.Egraph Methods showsPrec :: Int -> EClassData -> ShowS # show :: EClassData -> String # showList :: [EClassData] -> ShowS # | |||||
Eq EClassData Source # | |||||
Defined in Algorithm.EqSat.Egraph | |||||
type Rep EClassData Source # | |||||
Defined in Algorithm.EqSat.Egraph type Rep EClassData = D1 ('MetaData "EClassData" "Algorithm.EqSat.Egraph" "srtree-2.0.0.4-inplace" 'False) (C1 ('MetaCons "EData" 'PrefixI 'True) ((S1 ('MetaSel ('Just "_cost") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Cost) :*: (S1 ('MetaSel ('Just "_best") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ENode) :*: S1 ('MetaSel ('Just "_consts") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Consts))) :*: ((S1 ('MetaSel ('Just "_fitness") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe Double)) :*: S1 ('MetaSel ('Just "_dl") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe Double))) :*: (S1 ('MetaSel ('Just "_theta") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe PVector)) :*: S1 ('MetaSel ('Just "_size") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int))))) |
Serialization
Instances
Binary IntTrie Source # | |||||
Generic IntTrie Source # | |||||
Defined in Algorithm.EqSat.Egraph Associated Types
| |||||
Show IntTrie Source # | |||||
type Rep IntTrie Source # | |||||
Defined in Algorithm.EqSat.Egraph type Rep IntTrie = D1 ('MetaData "IntTrie" "Algorithm.EqSat.Egraph" "srtree-2.0.0.4-inplace" 'False) (C1 ('MetaCons "IntTrie" 'PrefixI 'True) (S1 ('MetaSel ('Just "_keys") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (HashSet EClassId)) :*: S1 ('MetaSel ('Just "_trie") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (IntMap IntTrie)))) |
E-Graph basic supporting functions
emptyGraph :: EGraph Source #
returns an empty e-graph
createEClass :: EClassId -> ENode -> EClassData -> Int -> EClass Source #
Creates a new e-class from an e-class id, a new e-node, and the info of this e-class
canonical :: forall (m :: Type -> Type). Monad m => EClassId -> EGraphST m EClassId Source #
gets the canonical id of an e-class
canonize :: forall (m :: Type -> Type). Monad m => ENode -> EGraphST m ENode Source #
canonize the e-node children
getEClass :: forall (m :: Type -> Type). Monad m => EClassId -> EGraphST m EClass Source #
gets an e-class with id c
isConst :: forall (m :: Type -> Type). Monad m => EClassId -> EGraphST m Bool Source #
Check whether an e-class is a constant value
Orphan instances
Binary PVector Source # | |||||
Hashable ENode Source # | |||||
Binary (SRTree EClassId) Source # | |||||
Binary (SRTree ()) Source # | |||||
(Binary a, Hashable a) => Binary (HashSet a) Source # | |||||
Generic (EClassId, ENode) Source # | |||||
Associated Types
|