pub struct RuleSet { /* private fields */ }Expand description
An ordered collection of Rules.
At each node the rules are tried in order and the first one that
applies wins. RuleSet is Clone + Send + Sync.
§Examples
use symplex::prelude::*;
use symplex::macros::{Rule, RuleSet};
let ctx = Context::new();
let (x, a) = (ctx.symbol("x"), ctx.symbol("a_"));
let rules = RuleSet::new()
.with(Rule::new("cos_sq", &a.cos().powi(2), &(1 - &a.sin().powi(2))))
.with(Rule::new("tan", &(&a.sin() / &a.cos()), &a.tan()));
assert_eq!(rules.len(), 2);
let expr = &x.cos().powi(2) + &x.sin() / &x.cos();
assert_eq!(format!("{}", expr.rewrite(&rules)), "-sin(x)^2 + tan(x) + 1");Implementations§
Source§impl RuleSet
impl RuleSet
Sourcepub fn from_rules(rules: Vec<Rule>) -> Self
pub fn from_rules(rules: Vec<Rule>) -> Self
Build from a vector of rules (order is preserved).
Sourcepub fn from_macro_rules(ctx: &Context, rules: Vec<Rule>) -> Self
pub fn from_macro_rules(ctx: &Context, rules: Vec<Rule>) -> Self
Wrap arena-level rules produced by the rule! macro.
§Examples
use symplex::prelude::*;
use symplex::macros::RuleSet;
let ctx = Context::new();
let x = ctx.symbol("x");
let raw = ctx.with_arena_mut(|arena| {
vec![
rule!(arena, "exp_ln", exp(ln(w_)) => w_),
rule!(arena, "sin_asin", sin(asin(w_)) => w_),
]
});
let rules = RuleSet::from_macro_rules(&ctx, raw);
assert_eq!(format!("{}", (&x.ln().exp() + &x.asin().sin()).rewrite(&rules)), "2*x");Trait Implementations§
Source§impl FromIterator<Rule> for RuleSet
impl FromIterator<Rule> for RuleSet
Auto Trait Implementations§
impl !RefUnwindSafe for RuleSet
impl !UnwindSafe for RuleSet
impl Freeze for RuleSet
impl Send for RuleSet
impl Sync for RuleSet
impl Unpin for RuleSet
impl UnsafeUnpin for RuleSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more