Skip to main content

Context

Struct Context 

Source
pub struct Context { /* private fields */ }
Expand description

表达式构造与求值的宿主。按问题作用域创建;Clone 得到共享同一 arena 的另一个入口(不复制数据)。

Implementations§

Source§

impl Context

Source

pub fn new() -> Self

Source

pub fn sym(&self, name: &str) -> Expr

声明符号。名字须匹配 [A-Za-z_][A-Za-z0-9_]*(违反属编程错误,直接 panic)。

Source

pub fn int(&self, v: i64) -> Expr

Source

pub fn integer(&self, v: &Integer) -> Expr

Source

pub fn sym_with(&self, name: &str, preds: &[Predicate]) -> Result<Expr, String>

带假设声明符号(D5):闭包补全(even⇒integer⇒…)+ 冲突检测; 同名重设不同假设报错(返回 Err 由调用方决定——MATLAB assume 的覆盖语义是有意不采用的,见 DESIGN D5)。

Source

pub fn query(&self, e: &Expr, p: Predicate) -> Trinary

三值假设查询(D5):True / False / Unknown。

Source

pub fn float(&self, v: f64) -> Expr

浮点字面量。负值返回 -1 * |v| 的规范形(Float 节点恒非负); NaN 属编程错误。

Source

pub fn rational(&self, n: i64, d: i64) -> Option<Expr>

有理数字面量;分母为零返回 None

Source

pub fn add(&self, args: &[Expr]) -> Expr

n 元加法(运算符重载的批量化入口)。

Source

pub fn mul(&self, args: &[Expr]) -> Expr

n 元乘法。

Source

pub fn pow(&self, base: &Expr, exp: &Expr) -> Expr

Source

pub fn call(&self, head: &str, args: &[Expr]) -> Expr

函数应用。参数保持语义次序(不排序);head 命名规则同符号。

Source

pub fn cmp_expr(&self, a: &Expr, b: &Expr) -> Ordering

表达式全序(同一 Context 内;跨 Context 用 Expr::eq 的结构比较)。

Source

pub fn eq_expr(&self, a: &Expr, b: &Expr) -> bool

Source

pub fn node_count(&self) -> usize

arena 规模(节点数;诊断与后续基准用)。

Source

pub fn inspect<R>(&self, f: impl FnOnce(&Inspector<'_>) -> R) -> R

只读检视。持有 Inspector 期间不可构造新表达式(构造方独占借用 arena)。

Source

pub fn expand(&self, e: &Expr) -> Expr

展开(L1):分配乘积 over 和式、展开非负整数幂(带规模守卫)、 函数参数内部展开。每步经规范形构造器,输出为规范形。

Source

pub fn cancel(&self, e: &Expr) -> Expr

有理函数约化(L1):分子分母的多项式公因子(gcd)约去。 非多项式因子原样保留;无可约化时返回与输入同一节点。

Source

pub fn factor(&self, e: &Expr) -> Expr

多项式因式分解(M4/M5):cont · Π 因子^重数,重建为规范形。 1/2 变元完全分解,≥3 变元部分(内容+平方自由);非多项式输入返回原节点。

Source

pub fn diff(&self, e: &Expr, x: &Expr) -> Expr

符号求导(P1):和/积/链式/幂(整数、有理、一般指数)与初等 函数表(sin cos tan exp log sqrt,abs→sign)。输出规范形。

Source

pub fn taylor(&self, e: &Expr, x: &Expr, at: i64, order: u32) -> Expr

Taylor 级数(P1):x=a 处的多项式部分到 (x−a)^order(含)。

Source

pub fn simplify(&self, e: &Expr) -> Expr

定向化简(P1,L2):常量折叠 + 无条件恒等式(sin²+cos²→1), 自底向上单遍,确定性输出。

Source

pub fn subst(&self, e: &Expr, map: &[(&str, Expr)]) -> Expr

代换:按符号名替换子表达式(替换值须属同一 Context)。 重建经规范形构造器,subst(e, x→x)e 同节点。

Source

pub fn eval_rational( &self, e: &Expr, vals: &[(&str, Rational)], ) -> Option<Rational>

ℚ 上精确求值。Float 字面量与函数节点返回 None(D2 域边界)。

Source

pub fn eval_float(&self, e: &Expr, vals: &[(&str, f64)]) -> Option<f64>

f64 数值求值(差分测试的语义判据通道)。支持初等函数头。

Source

pub fn monomial_coeffs( &self, e: &Expr, vars: &[&str], ) -> Result<Vec<(Vec<u32>, Expr)>, CasError>

e 视作 vars 的多项式,返回 (指数向量, 系数) 列表,指数按 vars 顺序。

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Context

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.