如何操作数学符号?
这更多的是一个“教育”问题。 :)
虽然,我最终可能想做这样的事情。
所以,假设我有一个方程。任何形式的方程都可以,只要它不是荒谬的,而且是一个擅长数学的人,都可以解出来。
比方说... 0 = (x-1)(x+2)
或... y = (x^2), y = 1/x
或正弦函数等。基本上,就像我们在学校做的那样做数学。
问题是,我该如何编写计算机程序来解决这个问题?我知道这是可能的,因为像 Mathematica、Maple 等程序几十年来一直在这样做!但我找不到任何关于如何制作简单方程求解器的好的文档。
我不期望答案告诉我“这正是你要做的”,因为当然这样的事情是一个完整的大型程序,而不仅仅是一个代码片段。
但只是一般概述,或者一些好的文档的链接?那太好了!谢谢:)
尤其是所需的数据结构和算法。
如果做不到这一点,我只需要弄清楚如何解方程,然后对其进行编码。但这实际上需要几个月的时间才能完成(我以前做过这种事情,将我自己的思维过程形式化为代码,它可以工作,但速度很慢)。
This is more of an "educational" question. :)
Although, I probably would like to do something like this eventually.
So, let's say I got an equation. Could be any kind of equation, as long as it's not ridiculous and also a human who was good at math, could solve it.
Let's say... 0 = (x-1)(x+2)
or... y = (x^2), y = 1/x
Or sine functions, etc. Basically, doing math like we did in school.
the question is, how would I write a computer program to solve this? I know it's possible, because programs like Mathematica, Maple, etc, have been doing this for decades! But I can't find any good documentation on how to make even a simple equation solver.
I don't expect answers that tell me "this is exactly how you do it" because of course such a thing is an entire large program, not just a code snippet.
But just a general overview, or links to some good documents? That would be great! Thanks :)
Especially the kind of data structures and algorithms needed.
Failing that, I'll just have to figure out HOW I SOLVE EQUATIONS, and encode that. But that takes literally months to get right (I've done this sort of thing before, formalising my own thinking process into code, it works but it's slow).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(4)
Wolfram Alpha 将是您最容易获得的基准测试。
您的输入是字符串,因此第一步是编写词法分析器/解析器以将这些字符串分解为标记并将它们放入抽象语法树 (AST) 中。
您没有说明要使用哪种语言来实现此功能,但我建议您查看 ANTLR。它是一个解析器生成器,可以帮助您创建 AST。你必须为你的方程想出一个语法。
一旦你有了 AST,你的解算器就会遍历树,并将更具体的操作与“+”、“-”等符号关联起来。你可以处理的运算符越多,你的解算器就会越强大、越全面。
但是,您必须处理或排除许多复杂情况:
- 并非所有方程都有解。
- 并非所有方程都有闭式解。
- 并非所有方程都是线性的。
- 许多有趣的问题由许多耦合方程组成(想想线性代数)。
- 当封闭式无法满足您的需求时,您可能需要了解很多有关数值方法的知识。
我建议您从简单的算术和多项式开始,然后逐步提高。史蒂芬·沃尔夫勒姆 (Stephen Wolfram) 并不是一天就能写出 Mathematica 的。
除了其他人的有用答案之外:此链接似乎很有趣: http://en.wikipedia.org/ wiki/Pattern_matching 另外,“抽象树语法”似乎很有趣。基本上,它是在语法树上进行“模式匹配”!有点像正则表达式,但用于代码。
我实际上已经编写了自己的“抽象树语法”:) 所以我已经在符号操纵器的道路上走了一小段路。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
查看一些关于符号操作的论文。
Peter Norvig 的 PAIP 书涵盖了一个非常简单的符号操作和方程求解系统,所以这是值得的一读。它介绍了名为 MacSyma 的人工智能程序的基础知识,该程序最终形成了 Mathematica。
Have a look at some papers on symbolic manipulation.
Peter Norvig's PAIP book covers a very simple system for symbolic manipulation and solving of equations, so that'd be worth a read. It introduces the basics of an AI program called MacSyma which eventually formed the basis of Mathematica.