Symbolica 2.0:面向 Python 和 Rust 的可编程符号
Symbolica 2.0: Programmable Symbols for Python and Rust

原始链接: https://symbolica.io/posts/symbolica_2_0_release/

Symbolica 2.0 现已发布,该版本显著增强了其用于 Python 和 Rust 的高性能符号计算框架。此次更新重点推出了“可编程符号”,允许用户直接在框架内定义自定义的数学行为,例如简化、微分和求值。 **主要改进包括:** * **可编程钩子 (Programmable Hooks):** 用户现在可以安装自定义逻辑,用于归一化、打印、级数展开(包括奇点)和数值评估。 * **增强的 Rust API:** 简化且更符合工程习惯的 API,具备更好的运算符重载、用于复杂配置的新构建器模式,以及更直观的“预导入”(prelude)。 * **高级求值器:** 框架现已支持 JIT 编译、高精度“双浮点”算术,以及扩充后的特殊函数库(如贝塞尔函数、黎曼 zeta 函数和多重对数函数)。 * **输出与易用性:** 新增对 LaTeX、Typst 以及彩色 HTML/Notebook 输出的支持,提升了大型嵌套表达式的可读性。 * **性能:** 通过对模式匹配、项排序和多项式算法的深度优化,用户在实际应用场景中可获得 2 倍至 10,000 倍的性能提升。 Symbolica 2.0 对业余爱好者和非商业单核使用保持免费,并提供商业许可模式以支持持续开发。

```Hacker News新 | 往期 | 评论 | 提问 | 展示 | 招聘 | 提交登录Symbolica 2.0:Python 和 Rust 的可编程符号 (symbolica.io)13 点,由 mmastrac 在 2 小时前发布 | 隐藏 | 往期 | 收藏 | 讨论 帮助 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:```
相关文章

原文

Introduction

Symbolica is a high-performance symbolic computation framework for Python and Rust. You can use it to manipulate symbolic expressions and turn them into fast numerical kernels for computing Jacobians, numerical optimization, integration, and much more.

Today marks the 2.0 release of Symbolica, with many exciting new features and improvements. The theme of this release is programmable symbols: more of Symbolica’s behavior can now be customized by the user. This makes it possible to define mathematical objects that simplify, differentiate, expand, print, and evaluate like built-ins.

Since 1.0, Symbolica has accumulated improvements in several directions:

  • a simpler Rust API with more operator overloading and builder-style APIs
  • a symbol registration system, with namespaces, aliases, tags, user data, and custom hooks
  • a redesigned evaluator interface that supports double-float arithmetic and JIT compilation
  • richer output for notebooks and documents, including HTML output, graph and polynomial display, Typst output, colorized printing, and more structural multiline formatting
  • new built-in mathematical functions, including gamma, polylogarithms, Bessel functions, Riemann zeta, and related series/evaluation hooks

See the migration guide to learn more about the changes and how to update your code.

Better output

Symbolica gained an automatic line-wrapping output mode, with colored brackets, similar to how code is styled. This makes it easier to read large, nested expressions. In notebooks, such as Jupyter or Marimo, the default output is a colorful HTML-mode and you can easily switch to LaTeX mode. Typst output is available now as well.

Improved Rust API

One of the most visible changes is that ordinary Rust programs need far fewer imports and fewer long type paths. The new prelude collects the common traits, macros, domains, and evaluator types that most users need. Rust ergonomics have also been improved with additional overloads, automatic type conversions, builder patterns, and a call method on symbols:

gamma function. Since gamma has a pole at 0, we cannot Taylor expand around 0. Using the series hook we can tell Symbolica how to regularize the function near that point by applying the identity \(\Gamma(a + 1) = a \Gamma(a)\):

this blog post for the details of how this works.

Evaluators for symbols

Let us define a custom symbol cosh and teach Symbolica how to evaluate it for different numeric domains. We can do this by registering an evaluation hook:

symjit crate by Shahriar Iravanian, with whom we worked closely to make the integration feel native to Symbolica.

The JIT path supports custom evaluator hooks and is now the default evaluation backend for Python. In practice, it is competitive with the custom ASM backend while keeping compilation times under control.

Double-float arithmetic

Symbolica 2.0 adds a double-float evaluation path. Double-float arithmetic stores a number as the unevaluated sum of two f64s, giving roughly 106 bits of precision (31 decimal digits compared to 16 for ordinary doubles) while staying more than 3x faster than arbitrary-precision Float arithmetic. In Python, evaluate_with_prec(..., 32) takes this path automatically.

Special functions

Another major development made possible by the new hook system is that Symbolica has grown a larger mathematical vocabulary. Symbolica now supports polygamma functions, polylogarithms, Bessel functions, Riemann zeta, geometric functions and their inverses, with evaluation hooks and Laurent/Puiseux series behavior around poles.

Some special values normalize immediately:

malachite and astro-float instead), which leads to a WASM-able Symbolica build (and easier compilation on Windows) at the expense of performance. Stay tuned for more details!

Symbolica is free for hobbyists and a single-core instance is free for non-commercial use. If you want new features, more documentation, or support for your workflow, your organization can purchase a license and directly support the project.

Closing

Symbolica 2.0 makes the symbolic system more programmable: users can teach symbols how to normalize, print, differentiate, expand around singularities, and evaluate numerically.

Let me know what you think in the comments!

联系我们 contact @ memedata.com