use super::SymExpr;
use crate::Float;
pub struct ExprBuilder<T: Float> {
expr: SymExpr<T>,
}
impl<T: Float> ExprBuilder<T> {
pub fn var(name: impl Into<String>) -> Self {
Self {
expr: SymExpr::variable(name),
}
}
pub fn constant(value: T) -> Self {
Self {
expr: SymExpr::constant(value),
}
}
#[allow(clippy::should_implement_trait)]
pub fn add(self, other: SymExpr<T>) -> Self {
Self {
expr: SymExpr::Add(Box::new(self.expr), Box::new(other)),
}
}
#[allow(clippy::should_implement_trait)]
pub fn mul(self, other: SymExpr<T>) -> Self {
Self {
expr: SymExpr::Mul(Box::new(self.expr), Box::new(other)),
}
}
pub fn pow(self, exponent: T) -> Self {
Self {
expr: SymExpr::Pow(Box::new(self.expr), Box::new(SymExpr::constant(exponent))),
}
}
pub fn build(self) -> SymExpr<T> {
self.expr
}
}
#[macro_export]
macro_rules! symexpr {
($var:ident) => {
$crate::symbolic::SymExpr::variable(stringify!($var))
};
($val:literal) => {
$crate::symbolic::SymExpr::constant($val)
};
}