| Crates.io | yufmath |
| lib.rs | yufmath |
| version | 0.1.1 |
| created_at | 2025-08-17 13:31:39.837645+00 |
| updated_at | 2025-08-17 14:01:44.689816+00 |
| description | A Rust CAS Lib. |
| homepage | |
| repository | https://github.com/Ceyase/yufmath |
| max_upload_size | |
| id | 1799409 |
| size | 1,884,837 |
Yufmath 是一个基于 Rust 编写的高性能计算机代数系统(CAS)库,提供符号数学计算、精确算术运算和多种接口支持。
本项目由 Kiro 提供部分支持
[!CAUTION] 这个库仍然处于不稳定状态
将以下内容添加到您的 Cargo.toml 文件中:
[dependencies]
yufmath = "0.1.0"
use yufmath::Yufmath;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let yuf = Yufmath::new();
// 基本计算
let result = yuf.compute("2 + 3 * 4")?;
println!("结果: {}", result); // 输出: 结果: 14
// 符号计算
let simplified = yuf.compute("x + x + 2*x")?;
println!("简化: {}", simplified); // 输出: 简化: 4*x
// 求导
let expr = yuf.parse("x^3 + 2*x^2 + x")?;
let derivative = yuf.diff(&expr, "x")?;
println!("导数: {}", yuf.formatter.format(&derivative)); // 输出: 导数: 3*x^2 + 4*x + 1
Ok(())
}
安装命令行工具:
cargo install yufmath
使用示例:
# 基本计算
yufmath compute "2^10 + 3^5"
# 表达式简化
yufmath simplify "(x+1)^2"
# 求导
yufmath diff "x^3 + sin(x)" x
# 积分
yufmath integrate "2*x + 1" x
# 交互模式
yufmath interactive
Yufmath 优先使用精确表示,支持:
use yufmath::{Yufmath, Number};
use num_bigint::BigInt;
let yuf = Yufmath::new();
// 大整数运算
let big_num = Number::integer(BigInt::from(2).pow(1000));
let result = yuf.compute(&format!("{} + 1", big_num))?;
// 精确有理数
let fraction = Number::rational(22, 7); // 22/7 的精确表示
支持各种符号数学运算:
let yuf = Yufmath::new();
// 代数简化
let expr = yuf.parse("(x + 1)^2")?;
let expanded = yuf.simplify(&expr)?; // x^2 + 2*x + 1
// 因式分解
let factored = yuf.compute("factor(x^2 - 4)")?; // (x - 2)(x + 2)
// 多项式运算
let collected = yuf.compute("collect(x^2 + 2*x + x^2, x)")?; // 2*x^2 + 2*x
let yuf = Yufmath::new();
// 符号求导
let expr = yuf.parse("sin(x^2) + cos(x)")?;
let derivative = yuf.diff(&expr, "x")?; // 2*x*cos(x^2) - sin(x)
// 符号积分
let integral = yuf.integrate(&yuf.parse("2*x + 1")?, "x")?; // x^2 + x + C
// 定积分(计划中的功能)
// let definite = yuf.definite_integral(&expr, "x", 0, 1)?;
Yufmath 采用模块化设计,主要组件包括:
core/):表达式、数值类型、运算符定义parser/):词法分析和语法分析engine/):数学运算和简化算法formatter/):多种输出格式支持api/):Rust 原生 APIcli/):交互式和批处理模式ffi/):C++ 语言绑定Yufmath 目前处于积极开发阶段。已完成的功能:
我们欢迎各种形式的贡献!请查看 CONTRIBUTING.md 了解如何参与项目开发。
本项目采用 MIT 许可证。详情请查看 LICENSE 文件。