Java:是否有可用的工具可以让我输入、存储和计算数学公式?

发布于 2024-07-11 14:15:47 字数 187 浏览 8 评论 0原文

即使是非常基本的东西也很好。 就像输入和评估类似 x+1 的东西一样,其中 x 是我要指定的变量。

我正在考虑为每个公式使用字符串、用于解析它们的正则表达式等来编写自己的代码,但是让我们假设我的目标是尽可能地懒惰,并且如果有另一种选择(尤其是正式的选择) ),我宁愿首先尝试使用它。

有没有什么东西可以做这样的事情?

Even something very rudimentary is fine. Like entering and evaluating something like x+1, where x is a variable I get to specify.

I was thinking of writing my own using Strings for each formula, regex for parsing them, etc., but let's assume my goal is to be as lazy as I can possibly get away with, and that if there's another option (especially a formal one), I'd rather try to use that instead, first.

Is there anything out there that does something like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

或十年 2024-07-18 14:15:47

我知道以下库:

I know the following libraries:

难如初 2024-07-18 14:15:47

您可以考虑使用 Java 6 中的脚本。参考 JDK 附带了 JavaScript 实现,您也可以插入其他语言。

You can think about using scripting from Java 6. The reference JDK comes with a JavaScript implementation, and you can plug in other languages too.

喵星人汪星人 2024-07-18 14:15:47

几年前我已经成功使用了JEP,并且它似乎仍在积极开发中。 我相信当时他们有更宽松的许可证,但它可能比自己编码更便宜(取决于您的具体需求和技能)。

I've used JEP with success a couple of years ago and it still seems to be actively developed. I believe they had a more permissive license back in those days, but it's probably cheaper than coding it yourself (depending on your exact needs and skills).

还如梦归 2024-07-18 14:15:47

我已经为自己构建了一个 java 库来完成此任务,作为 Lex/YACC 的学习示例。 它被合并到一个更大的项目中,看起来效果很好。 如果我再次启动更大的项目,我会遵循上面的建议并使用 Java 脚本引擎。

I've built a java library to do exactly this as a learning example for Lex/YACC, for myself. It was incorporated into a larger project, where it seems to work well. Were I to start the larger project again, I'd follow the advice above and use the Java scripting engine.

避讳 2024-07-18 14:15:47

您可以尝试 LibFormula,一个基于OpenDocument 的 OpenFormula 标准。

OpenFormula 是为电子表格应用程序编写的,并使用接近 Excel 公式的语法。 更多信息可以在 Pentaho-Wiki 示例中找到

=[x]+1

You could try LibFormula, a formula eavluation library that's based on OpenDocument's OpenFormula standard.

OpenFormula was written for spreadsheet applications and uses a syntax close to Excel-formulas. More info can be found in the Pentaho-Wiki

Sample:

=[x]+1
别靠近我心 2024-07-18 14:15:47

您可以查看我在 Apache 许可证 2.0。 它实现了 dijkstra 的调车场算法,并且可以很好地与诸如 f(x,foo)=log(foo^(x^-1))

you can check out exp4j which i released under the Apache License 2.0. it implements dijkstra's shunting yard algorithm, and works well with multivariable functions like f(x,foo)=log(foo^(x^-1))

汹涌人海 2024-07-18 14:15:47

有些人可能对名为 formula4j 的新工具感兴趣。

它是商业性的,所以并不适合所有人。

Some may be interested in a new tool called formula4j.

It's commercial, so it's not for everyone.

忱杏 2024-07-18 14:15:47

也许MathML

MathML 是一种低级规范,用于将数学描述为机器对机器通信的基础,它为在网页中包含数学表达式提供了急需的基础。 它对于发布科学技术工作流程以及任何需要由软件处理数学的地方也很重要。 例如,新版本改进了数学的可访问性以及从右到左编写的语言中的公式。 基本标记保持不变,因为社区拥有七年的经验。

Maybe MathML?

MathML is a low-level specification for describing mathematics as a basis for machine to machine communication which provides a much needed foundation for the inclusion of mathematical expressions in Web pages. It is also important in publishing workflows for science and technology and wherever mathematics has to be handled by software. The new version brings, for instance, improvements for accessibility of mathematics, and for formulas in languages written from right to left. The basic markup remains the same, as the community have seven years of experience with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文