Struct egg::MultiPattern

source ·
pub struct MultiPattern<L> { /* private fields */ }
Expand description

A set of open expressions bound to variables.

Multipatterns bind many expressions to variables, allowing for simulataneous searching or application of many terms constrained to the same substitution.

Multipatterns are good for writing graph rewrites or datalog-style rules.

You can create multipatterns via the MultiPattern::new function or the multi_rewrite! macro.

MultiPattern implements both Searcher and Applier. When searching a multipattern, the result ensures that patterns bound to the same variable are equivalent. When applying a mulitpattern, patterns bound a variable occuring in the searcher are unioned with that e-class.

Multipatterns currently do not support the explanations feature.

Implementations§

Creates a new multipattern, binding the given patterns to the corresponding variables.

use egg::*;

let mut egraph = EGraph::<SymbolLang, ()>::default();
egraph.add_expr(&"(f a a)".parse().unwrap());
egraph.add_expr(&"(f a b)".parse().unwrap());
egraph.add_expr(&"(g a a)".parse().unwrap());
egraph.add_expr(&"(g a b)".parse().unwrap());
egraph.rebuild();

let f_pat: PatternAst<SymbolLang> = "(f ?x ?y)".parse().unwrap();
let g_pat: PatternAst<SymbolLang> = "(g ?x ?y)".parse().unwrap();
let v1: Var = "?v1".parse().unwrap();
let v2: Var = "?v2".parse().unwrap();

let multipattern = MultiPattern::new(vec![(v1, f_pat), (v2, g_pat)]);
// you can also parse multipatterns
assert_eq!(multipattern, "?v1 = (f ?x ?y), ?v2 = (g ?x ?y)".parse().unwrap());

assert_eq!(multipattern.n_matches(&egraph), 2);

Trait Implementations§

Apply a single substitition. Read more
Apply many substititions. Read more
Returns a list of variables that this Applier assumes are bound. Read more
For patterns, get the ast directly as a reference.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Similar to search_eclass, but return at most limit many matches. Read more
Returns a list of the variables bound by this Searcher
Search one eclass, returning None if no matches can be found. This should not return a SearchMatches with no substs. Read more
Search the whole EGraph, returning a list of all the SearchMatches where something was found. This just calls search_eclass on each eclass. Read more
Similar to search, but return at most limit many matches. Read more
Returns the number of matches in the e-graph
For patterns, return the ast directly as a reference

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.