[−][src]Struct egg::Pattern
A pattern that can function as either a Searcher
or Applier
.
A Pattern
is essentially a for-all quantified expression with
Var
s as the variables (in the logical sense).
When creating a Rewrite
, the most common thing to use as either
the left hand side (the Searcher
) or the right hand side
(the Applier
) is a Pattern
.
As a Searcher
, a Pattern
does the intuitive
thing.
Here is a somewhat verbose formal-ish statement:
Searching for a pattern in an egraph yields substitutions
(Subst
s) s such that, for any s'—where instead of
mapping a variables to an eclass as s does, s' maps
a variable to an arbitrary expression represented by that
eclass—p[s'] (the pattern under substitution s') is also
represented by the egraph.
As an Applier
, a Pattern
performs the given substitution
and adds the result to the EGraph
.
Importantly, Pattern
implements FromStr
if the
Language
does.
This is probably how you'll create most Pattern
s.
use egg::*; define_language! { enum Math { Num(i32), "+" = Add([Id; 2]), } } let mut egraph = EGraph::<Math, ()>::default(); let a11 = egraph.add_expr(&"(+ 1 1)".parse().unwrap()); let a22 = egraph.add_expr(&"(+ 2 2)".parse().unwrap()); // use Var syntax (leading question mark) to get a // variable in the Pattern let same_add: Pattern<Math> = "(+ ?a ?a)".parse().unwrap(); // Rebuild before searching egraph.rebuild(); // This is the search method from the Searcher trait let matches = same_add.search(&egraph); let matched_eclasses: Vec<Id> = matches.iter().map(|m| m.eclass).collect(); assert_eq!(matched_eclasses, vec![a11, a22]);
Trait Implementations
impl<L, A> Applier<L, A> for Pattern<L> where
L: Language,
A: Analysis<L>,
[src]
L: Language,
A: Analysis<L>,
fn apply_one(&self, egraph: &mut EGraph<L, A>, _: Id, subst: &Subst) -> Vec<Id>
[src]
fn apply_matches(
&self,
egraph: &mut EGraph<L, N>,
matches: &[SearchMatches]
) -> Vec<Id>
[src]
&self,
egraph: &mut EGraph<L, N>,
matches: &[SearchMatches]
) -> Vec<Id>
impl<N: Clone> Clone for Pattern<N>
[src]
impl<N: Debug> Debug for Pattern<N>
[src]
impl<'a, L: Language> From<&'a [L]> for Pattern<L>
[src]
impl<L: Language> FromStr for Pattern<L>
[src]
type Err = String
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl<N: PartialEq> PartialEq<Pattern<N>> for Pattern<N>
[src]
impl<L: Language, A: Analysis<L>> Searcher<L, A> for Pattern<L>
[src]
fn search(&self, egraph: &EGraph<L, A>) -> Vec<SearchMatches>
[src]
fn search_eclass(
&self,
egraph: &EGraph<L, A>,
eclass: Id
) -> Option<SearchMatches>
[src]
&self,
egraph: &EGraph<L, A>,
eclass: Id
) -> Option<SearchMatches>
impl<N> StructuralPartialEq for Pattern<N>
[src]
impl<L: Language> TryFrom<Pattern<L>> for RecExpr<L>
[src]
Auto Trait Implementations
impl<N> RefUnwindSafe for Pattern<N> where
N: RefUnwindSafe,
N: RefUnwindSafe,
impl<N> Send for Pattern<N> where
N: Send,
N: Send,
impl<N> Sync for Pattern<N> where
N: Sync,
N: Sync,
impl<N> Unpin for Pattern<N> where
N: Unpin,
N: Unpin,
impl<N> UnwindSafe for Pattern<N> where
N: UnwindSafe,
N: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,