#![allow(deprecated)]
use std::collections::BTreeMap;
use std::fmt::Debug;
use std::fmt::Write;
use std::hash::Hash;
use std::hash::Hasher;
use std::sync::Arc;
use num_bigint::BigInt;
use num_rational::BigRational;
use super::dag_mgr::DagNode;
use crate::symbolic::unit_unification::UnitQuantity;
pub trait Distribution:
Debug + Send + Sync + std::panic::RefUnwindSafe + std::panic::UnwindSafe
{
fn pdf(
&self,
x: &Expr,
) -> Expr;
fn cdf(
&self,
x: &Expr,
) -> Expr;
fn expectation(&self) -> Expr;
fn variance(&self) -> Expr;
fn mgf(
&self,
t: &Expr,
) -> Expr;
fn clone_box(&self) -> Arc<dyn Distribution>;
}
#[derive(
Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
)]
pub enum PathType {
Line,
Circle,
Rectangle,
}
#[derive(
Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
)]
pub struct Monomial(pub BTreeMap<String, u32>);
#[derive(
Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, PartialOrd, Ord,
)]
pub struct SparsePolynomial {
pub terms: BTreeMap<Monomial, Expr>,
}
#[derive(serde::Serialize, serde::Deserialize)]
pub enum Expr {
Constant(f64),
BigInt(BigInt),
Rational(BigRational),
Boolean(bool),
Variable(String),
Pattern(String),
Add(Arc<Self>, Arc<Self>),
Sub(Arc<Self>, Arc<Self>),
Mul(Arc<Self>, Arc<Self>),
Div(Arc<Self>, Arc<Self>),
Power(Arc<Self>, Arc<Self>),
Neg(Arc<Self>),
AddList(Vec<Self>),
MulList(Vec<Self>),
Sin(Arc<Self>),
Cos(Arc<Self>),
Tan(Arc<Self>),
Exp(Arc<Self>),
Log(Arc<Self>),
Abs(Arc<Self>),
Sqrt(Arc<Self>),
Eq(Arc<Self>, Arc<Self>),
Lt(Arc<Self>, Arc<Self>),
Gt(Arc<Self>, Arc<Self>),
Le(Arc<Self>, Arc<Self>),
Ge(Arc<Self>, Arc<Self>),
Matrix(Vec<Vec<Self>>),
Vector(Vec<Self>),
Complex(Arc<Self>, Arc<Self>),
Transpose(Arc<Self>),
MatrixMul(Arc<Self>, Arc<Self>),
MatrixVecMul(Arc<Self>, Arc<Self>),
Inverse(Arc<Self>),
Derivative(Arc<Self>, String),
DerivativeN(Arc<Self>, String, Arc<Self>),
Integral {
integrand: Arc<Self>,
var: Arc<Self>,
lower_bound: Arc<Self>,
upper_bound: Arc<Self>,
},
VolumeIntegral {
scalar_field: Arc<Self>,
volume: Arc<Self>,
},
SurfaceIntegral {
vector_field: Arc<Self>,
surface: Arc<Self>,
},
Limit(Arc<Self>, String, Arc<Self>),
Sum {
body: Arc<Self>,
var: Arc<Self>,
from: Arc<Self>,
to: Arc<Self>,
},
Series(Arc<Self>, String, Arc<Self>, Arc<Self>),
Summation(Arc<Self>, String, Arc<Self>, Arc<Self>),
Product(Arc<Self>, String, Arc<Self>, Arc<Self>),
ConvergenceAnalysis(Arc<Self>, String),
AsymptoticExpansion(Arc<Self>, String, Arc<Self>, Arc<Self>),
Sec(Arc<Self>),
Csc(Arc<Self>),
Cot(Arc<Self>),
ArcSin(Arc<Self>),
ArcCos(Arc<Self>),
ArcTan(Arc<Self>),
ArcSec(Arc<Self>),
ArcCsc(Arc<Self>),
ArcCot(Arc<Self>),
Sinh(Arc<Self>),
Cosh(Arc<Self>),
Tanh(Arc<Self>),
Sech(Arc<Self>),
Csch(Arc<Self>),
Coth(Arc<Self>),
ArcSinh(Arc<Self>),
ArcCosh(Arc<Self>),
ArcTanh(Arc<Self>),
ArcSech(Arc<Self>),
ArcCsch(Arc<Self>),
ArcCoth(Arc<Self>),
LogBase(Arc<Self>, Arc<Self>),
Atan2(Arc<Self>, Arc<Self>),
Binomial(Arc<Self>, Arc<Self>),
Factorial(Arc<Self>),
Permutation(Arc<Self>, Arc<Self>),
Combination(Arc<Self>, Arc<Self>),
FallingFactorial(Arc<Self>, Arc<Self>),
RisingFactorial(Arc<Self>, Arc<Self>),
Path(PathType, Arc<Self>, Arc<Self>),
Boundary(Arc<Self>),
Domain(String),
Pi,
E,
Infinity,
NegativeInfinity,
Gamma(Arc<Self>),
Beta(Arc<Self>, Arc<Self>),
Erf(Arc<Self>),
Erfc(Arc<Self>),
Erfi(Arc<Self>),
Zeta(Arc<Self>),
BesselJ(Arc<Self>, Arc<Self>),
BesselY(Arc<Self>, Arc<Self>),
LegendreP(Arc<Self>, Arc<Self>),
LaguerreL(Arc<Self>, Arc<Self>),
HermiteH(Arc<Self>, Arc<Self>),
Digamma(Arc<Self>),
KroneckerDelta(Arc<Self>, Arc<Self>),
And(Vec<Self>),
Or(Vec<Self>),
Not(Arc<Self>),
Xor(Arc<Self>, Arc<Self>),
Implies(Arc<Self>, Arc<Self>),
Equivalent(Arc<Self>, Arc<Self>),
Predicate {
name: String,
args: Vec<Self>,
},
ForAll(String, Arc<Self>),
Exists(String, Arc<Self>),
Union(Vec<Self>),
Interval(Arc<Self>, Arc<Self>, bool, bool),
Polynomial(Vec<Self>),
SparsePolynomial(SparsePolynomial),
Floor(Arc<Self>),
IsPrime(Arc<Self>),
Gcd(Arc<Self>, Arc<Self>),
Mod(Arc<Self>, Arc<Self>),
Solve(Arc<Self>, String),
Substitute(Arc<Self>, String, Arc<Self>),
System(Vec<Self>),
Solutions(Vec<Self>),
ParametricSolution {
x: Arc<Self>,
y: Arc<Self>,
},
RootOf {
poly: Arc<Self>,
index: u32,
},
InfiniteSolutions,
NoSolution,
Ode {
equation: Arc<Self>,
func: String,
var: String,
},
Pde {
equation: Arc<Self>,
func: String,
vars: Vec<String>,
},
GeneralSolution(Arc<Self>),
ParticularSolution(Arc<Self>),
Fredholm(Arc<Self>, Arc<Self>, Arc<Self>, Arc<Self>),
Volterra(Arc<Self>, Arc<Self>, Arc<Self>, Arc<Self>),
Apply(Arc<Self>, Arc<Self>),
Tuple(Vec<Self>),
Dag(Arc<DagNode>),
#[serde(skip_serializing, skip_deserializing)]
Distribution(Arc<dyn Distribution>),
Max(Arc<Self>, Arc<Self>),
Quantity(Arc<UnitQuantity>),
QuantityWithValue(Arc<Self>, String),
#[deprecated(
since = "0.1.18",
note = "Please use the \
'UnaryList' variant \
instead."
)]
CustomZero,
#[deprecated(
since = "0.1.18",
note = "Please use the \
'UnaryList' variant \
instead."
)]
CustomString(String),
#[deprecated(
since = "0.1.18",
note = "Please use the \
'UnaryList' variant \
instead."
)]
CustomArcOne(Arc<Self>),
#[deprecated(
since = "0.1.18",
note = "Please use the \
'BinaryList' variant \
instead."
)]
CustomArcTwo(Arc<Self>, Arc<Self>),
#[deprecated(
since = "0.1.18",
note = "Please use the \
'NaryList' variant \
instead."
)]
CustomArcThree(Arc<Self>, Arc<Self>, Arc<Self>),
#[deprecated(
since = "0.1.18",
note = "Please use the \
'NaryList' variant \
instead."
)]
CustomArcFour(Arc<Self>, Arc<Self>, Arc<Self>, Arc<Self>),
#[deprecated(
since = "0.1.18",
note = "Please use the \
'NaryList' variant \
instead."
)]
CustomArcFive(Arc<Self>, Arc<Self>, Arc<Self>, Arc<Self>, Arc<Self>),
#[deprecated(
since = "0.1.18",
note = "Please use the \
'UnaryList' variant \
instead."
)]
CustomVecOne(Vec<Self>),
#[deprecated(
since = "0.1.18",
note = "Please use the \
'BinaryList' variant \
instead."
)]
CustomVecTwo(Vec<Self>, Vec<Self>),
#[deprecated(
since = "0.1.18",
note = "Please use the \
'NaryList' variant \
instead."
)]
CustomVecThree(Vec<Self>, Vec<Self>, Vec<Self>),
#[deprecated(
since = "0.1.18",
note = "Please use the \
'NaryList' variant \
instead."
)]
CustomVecFour(Vec<Self>, Vec<Self>, Vec<Self>, Vec<Self>),
#[deprecated(
since = "0.1.18",
note = "Please use the \
'NaryList' variant \
instead."
)]
CustomVecFive(Vec<Self>, Vec<Self>, Vec<Self>, Vec<Self>, Vec<Self>),
UnaryList(String, Arc<Self>),
BinaryList(String, Arc<Self>, Arc<Self>),
NaryList(String, Vec<Self>),
}