Java:是否有可用的工具可以让我输入、存储和计算数学公式?
即使是非常基本的东西也很好。 就像输入和评估类似 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我知道以下库:
Symja Parser (GPL 许可证)支持 Mathematica 类似语法
Jep - Java 数学表达式解析器(商业 - GNU 公共许可证下的旧版本?)
JFormula(商业)
MathEval - 数学表达式计算器(公共领域和非常小的足迹)
I know the following libraries:
Symja Parser (GPL License) supports Mathematica like syntax
Jep - Java Math Expression Parser (commercial - older versions under GNU Public License?)
JFormula (commercial)
MathEval - Math Expression Evaluator (public domain and very small footprint)
您可以考虑使用 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.
几年前我已经成功使用了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).
我已经为自己构建了一个 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.
您可以尝试 LibFormula,一个基于OpenDocument 的 OpenFormula 标准。
OpenFormula 是为电子表格应用程序编写的,并使用接近 Excel 公式的语法。 更多信息可以在 Pentaho-Wiki 示例中找到
:
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:
您可以查看我在 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))
有些人可能对名为 formula4j 的新工具感兴趣。
它是商业性的,所以并不适合所有人。
Some may be interested in a new tool called formula4j.
It's commercial, so it's not for everyone.
也许MathML?
Maybe MathML?