允许将数值公式视为对象的开源语言/库/表示格式?
我正在寻找一种将一系列公式/方程存储为文本的方法(以便它们可以轻松区分)。后面的公式取决于前面公式的结果。
我应该能够将公式(类似于 MathCAD 中的实时工作表)计算为数值结果,而且还能够以编程方式生成原始公式的字符串表示形式。
换句话说,我希望能够将公式本身视为数据,并评估公式。
我想要一个在编辑公式时具有语法突出显示功能的文本编辑器。
我的第一种方法是创建一个 Python 文件,其中的公式存储为字符串,然后对字符串调用 eval()
。但是,这不允许对公式进行语法突出显示。
我选择的语言是 Python,但我愿意接受其他非专有解决方案。
示例:
a = 73
b = 13
c = 100
d = 20
e = 18
x = a^2 + b / (c - min(d, e))
y = c + sqrt(x * e)
目的是使用公式的计算结果自动生成其他代码,同时使用原始公式本身注释生成的代码。
I'm looking for a way to store a series of formulas/equations as text (so they are easily diff-able). Later formulas depend on the results of earlier ones.
I should be able to evaluate the formulas (similar to Live Worksheets in MathCAD) to numeric results, but also be able to programmatically produce a string representation of the original formula.
Put another way, I'd like to be able to treat the formulas themselves as data, as well as evaluate the formulas.
I would like to have a text editor with syntax highlighting when editing the formulas.
My first approach was to have a Python file with the formulas stored as strings, then call eval()
on the strings. However, this does not allow for syntax highlighting of the formulas.
My language of choice is Python, but I would be open to other non-proprietary solutions.
Example:
a = 73
b = 13
c = 100
d = 20
e = 18
x = a^2 + b / (c - min(d, e))
y = c + sqrt(x * e)
The intent is to automatically generate other code using the evaluated results of the formulas, while commenting that generated code with the original formulas themselves.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 sympy:
输出为:
you can use sympy:
the output is: