[][src]Enum egg::Pattern

#[non_exhaustive]
pub enum Pattern<L> {
    // some variants omitted
}

A pattern that can function as either a Searcher or Applier.

A Pattern is essentially a for-all quantified expression with QuestionMarkNames 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 (a.k.a WildMaps) 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 Patterns.

use egg::*;
define_language! {
    enum Math {
        Num(i32),
        Add = "+",
    }
}

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 QuestionMarkName syntax (leading question mark) to get a
// variable in the Pattern
let same_add: Pattern<Math> = "(+ ?a ?a)".parse().unwrap();

// 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: Language, M: Metadata<L>> Applier<L, M> for Pattern<L>[src]

impl<L: Clone> Clone for Pattern<L>[src]

impl<L: Debug> Debug for Pattern<L>[src]

impl<L: Language> From<RecExpr<L>> for Pattern<L>[src]

impl<L: Language + FromStr> FromStr for Pattern<L>[src]

type Err = ParseError

The associated error which can be returned from parsing.

impl<L: PartialEq> PartialEq<Pattern<L>> for Pattern<L>[src]

impl<L, M> Searcher<L, M> for Pattern<L> where
    L: Language,
    M: Metadata<L>, 
[src]

impl<L> StructuralPartialEq for Pattern<L>[src]

impl<L: Language> TryFrom<Pattern<L>> for RecExpr<L>[src]

type Error = String

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<L> !RefUnwindSafe for Pattern<L>

impl<L> !Send for Pattern<L>

impl<L> !Sync for Pattern<L>

impl<L> Unpin for Pattern<L>

impl<L> !UnwindSafe for Pattern<L>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.