Enum mz_transform::symbolic::SymbolicExpression
source · pub enum SymbolicExpression<V> {
Constant(OrderedFloat<f64>),
Symbolic(V, usize),
Sum(Vec<SymbolicExpression<V>>),
Product(Vec<SymbolicExpression<V>>),
Max(Box<SymbolicExpression<V>>, Box<SymbolicExpression<V>>),
Min(Box<SymbolicExpression<V>>, Box<SymbolicExpression<V>>),
}
Expand description
Symbolic algebraic expressions over variables V
Variants§
Constant(OrderedFloat<f64>)
A constant expression
Symbolic(V, usize)
Variable(x, n)
represents x^n
Sum(Vec<SymbolicExpression<V>>)
Sum([e_1, ..., e_m])
represents e_1 + … + e_m
Product(Vec<SymbolicExpression<V>>)
Product([e_1, ..., e_m])
represents e_1 * … * e_m
Max(Box<SymbolicExpression<V>>, Box<SymbolicExpression<V>>)
The maximum value of two expressions
Min(Box<SymbolicExpression<V>>, Box<SymbolicExpression<V>>)
The minimum value of two expressions
Implementations§
source§impl SymbolicExpression<FactorizerVariable>
impl SymbolicExpression<FactorizerVariable>
sourcepub fn humanize(&self, h: &dyn ExprHumanizer, f: &mut Formatter<'_>) -> Result
pub fn humanize(&self, h: &dyn ExprHumanizer, f: &mut Formatter<'_>) -> Result
Render a symbolic expression nicely
source§impl<V> SymbolicExpression<V>
impl<V> SymbolicExpression<V>
sourcepub fn evaluate<F>(&self, concretize: &F) -> f64
pub fn evaluate<F>(&self, concretize: &F) -> f64
Evaluates a symbolic expression, given a way to concretize
its symbolic parts
sourcepub fn order(&self) -> usize
pub fn order(&self) -> usize
Computes the order of a symbolic expression
use mz_transform::symbolic::SymbolicExpression;
let x = SymbolicExpression::symbolic("x".to_string());
let y = SymbolicExpression::symbolic("y".to_string());
// x^3 + xy + 1000000
let e = SymbolicExpression::sum(vec![SymbolicExpression::product(vec![x.clone(); 3]), SymbolicExpression::product(vec![x, y]), SymbolicExpression::f64(1000000.0)]);
// has order 3
assert_eq!(e.order(), 3);
sourcepub fn collect_symbolics(&self, symbolics: &mut BTreeSet<V>)
pub fn collect_symbolics(&self, symbolics: &mut BTreeSet<V>)
Collects all symbolic values in the expression
use mz_transform::symbolic::SymbolicExpression;
let x = SymbolicExpression::symbolic("x".to_string());
let y = SymbolicExpression::symbolic("y".to_string());
// x^3 + xy + 1000000
let e = SymbolicExpression::sum(vec![SymbolicExpression::product(vec![x.clone(); 3]), SymbolicExpression::product(vec![x, y]), SymbolicExpression::f64(1000000.0)]);
// has order 3
let mut symbolics = std::collections::BTreeSet::new();
e.collect_symbolics(&mut symbolics);
assert_eq!(symbolics.len(), 2);
assert!(symbolics.contains(&"x".to_string()));
assert!(symbolics.contains(&"y".to_string()));
sourcepub fn normalize(&self) -> Self
pub fn normalize(&self) -> Self
Walks the entire term, simplifying away redundancies that may have accumulated
sourcepub fn i64(n: i64) -> Self
pub fn i64(n: i64) -> Self
Generate a symbolic expression from an i64
(may be lossy for high values)
sourcepub fn usize(n: usize) -> Self
pub fn usize(n: usize) -> Self
Generate a symbolic expression from a usize
(may be lossy for high values)
sourcepub fn symbolic(v: V) -> Selfwhere
V: Ord,
pub fn symbolic(v: V) -> Selfwhere
V: Ord,
References a variable (with a default exponent of 1)
sourcepub fn max(e1: Self, e2: Self) -> Selfwhere
V: PartialOrd + PartialEq,
pub fn max(e1: Self, e2: Self) -> Selfwhere
V: PartialOrd + PartialEq,
Computes the maximum of two symbolic expressions
sourcepub fn min(e1: Self, e2: Self) -> Selfwhere
V: PartialOrd + PartialEq,
pub fn min(e1: Self, e2: Self) -> Selfwhere
V: PartialOrd + PartialEq,
Computes the minimum of two symbolic expressions
Trait Implementations§
source§impl<V> Add<SymbolicExpression<V>> for f64
impl<V> Add<SymbolicExpression<V>> for f64
§type Output = SymbolicExpression<V>
type Output = SymbolicExpression<V>
+
operator.source§impl<V> Add<f64> for SymbolicExpression<V>
impl<V> Add<f64> for SymbolicExpression<V>
source§impl<V> Add for &SymbolicExpression<V>
impl<V> Add for &SymbolicExpression<V>
source§impl<V> Add for SymbolicExpression<V>
impl<V> Add for SymbolicExpression<V>
source§impl<V: Clone> Clone for SymbolicExpression<V>
impl<V: Clone> Clone for SymbolicExpression<V>
source§fn clone(&self) -> SymbolicExpression<V>
fn clone(&self) -> SymbolicExpression<V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<V: Debug> Debug for SymbolicExpression<V>
impl<V: Debug> Debug for SymbolicExpression<V>
source§impl<V> Default for SymbolicExpression<V>
impl<V> Default for SymbolicExpression<V>
source§impl<V> Div<f64> for &SymbolicExpression<V>
impl<V> Div<f64> for &SymbolicExpression<V>
source§impl<V> Div<f64> for SymbolicExpression<V>
impl<V> Div<f64> for SymbolicExpression<V>
source§impl<V> From<f64> for SymbolicExpression<V>
impl<V> From<f64> for SymbolicExpression<V>
source§impl<V> From<i64> for SymbolicExpression<V>
impl<V> From<i64> for SymbolicExpression<V>
source§impl<V> From<usize> for SymbolicExpression<V>
impl<V> From<usize> for SymbolicExpression<V>
source§impl<V> Mul<&SymbolicExpression<V>> for f64
impl<V> Mul<&SymbolicExpression<V>> for f64
§type Output = SymbolicExpression<V>
type Output = SymbolicExpression<V>
*
operator.source§impl<V> Mul<SymbolicExpression<V>> for f64
impl<V> Mul<SymbolicExpression<V>> for f64
§type Output = SymbolicExpression<V>
type Output = SymbolicExpression<V>
*
operator.source§impl<V> Mul<f64> for &SymbolicExpression<V>
impl<V> Mul<f64> for &SymbolicExpression<V>
source§impl<V> Mul<f64> for SymbolicExpression<V>
impl<V> Mul<f64> for SymbolicExpression<V>
source§impl<V> Mul for &SymbolicExpression<V>
impl<V> Mul for &SymbolicExpression<V>
source§impl<V> Mul for SymbolicExpression<V>
impl<V> Mul for SymbolicExpression<V>
source§impl<V: Ord> Ord for SymbolicExpression<V>
impl<V: Ord> Ord for SymbolicExpression<V>
source§fn cmp(&self, other: &SymbolicExpression<V>) -> Ordering
fn cmp(&self, other: &SymbolicExpression<V>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<V: PartialEq> PartialEq for SymbolicExpression<V>
impl<V: PartialEq> PartialEq for SymbolicExpression<V>
source§fn eq(&self, other: &SymbolicExpression<V>) -> bool
fn eq(&self, other: &SymbolicExpression<V>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<V: PartialOrd> PartialOrd for SymbolicExpression<V>
impl<V: PartialOrd> PartialOrd for SymbolicExpression<V>
source§fn partial_cmp(&self, other: &SymbolicExpression<V>) -> Option<Ordering>
fn partial_cmp(&self, other: &SymbolicExpression<V>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<V> Sub<SymbolicExpression<V>> for f64
impl<V> Sub<SymbolicExpression<V>> for f64
§type Output = SymbolicExpression<V>
type Output = SymbolicExpression<V>
-
operator.source§impl<V> Sub<f64> for SymbolicExpression<V>
impl<V> Sub<f64> for SymbolicExpression<V>
source§impl<V> Sub for SymbolicExpression<V>
impl<V> Sub for SymbolicExpression<V>
impl<V: Eq> Eq for SymbolicExpression<V>
impl<V> StructuralPartialEq for SymbolicExpression<V>
Auto Trait Implementations§
impl<V> Freeze for SymbolicExpression<V>where
V: Freeze,
impl<V> RefUnwindSafe for SymbolicExpression<V>where
V: RefUnwindSafe,
impl<V> Send for SymbolicExpression<V>where
V: Send,
impl<V> Sync for SymbolicExpression<V>where
V: Sync,
impl<V> Unpin for SymbolicExpression<V>where
V: Unpin,
impl<V> UnwindSafe for SymbolicExpression<V>where
V: UnwindSafe,
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
source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<R, O, T> CopyOnto<ConsecutiveOffsetPairs<R, O>> for T
impl<R, O, T> CopyOnto<ConsecutiveOffsetPairs<R, O>> for T
source§fn copy_onto(
self,
target: &mut ConsecutiveOffsetPairs<R, O>
) -> <ConsecutiveOffsetPairs<R, O> as Region>::Index
fn copy_onto( self, target: &mut ConsecutiveOffsetPairs<R, O> ) -> <ConsecutiveOffsetPairs<R, O> as Region>::Index
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
source§impl<T, U> OverrideFrom<Option<&T>> for Uwhere
U: OverrideFrom<T>,
impl<T, U> OverrideFrom<Option<&T>> for Uwhere
U: OverrideFrom<T>,
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> PreferredContainer for T
impl<T> PreferredContainer for T
source§impl<T> ProgressEventTimestamp for T
impl<T> ProgressEventTimestamp for T
source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
RustType::from_proto
.source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
RustType::into_proto
.source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.