表达式简化算法 [英] Expression Simplification Algorithm

查看:155
本文介绍了表达式简化算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用计算器"应用,并且希望输出以简化表达式和十进制答案的形式出现.一个示例是sqrt 2 * sqrt 3 = sqrt 6,也可以将其输出为2.44948 ...最好的方法是什么?是否有完善的算法可以做到这一点?

I'm currently working on a Calculator app and I want output to be in both a simplified expression and decimal answer form. An example would be sqrt 2 * sqrt 3 = sqrt 6 which can also be outputted as 2.44948... What is the best approach to this and is there any well-established algorithms to do this?

推荐答案

是.您可能想要的是一个计算机代数系统,该系统将公式理解为要由显式数学处理的伪像.规则.

Yes. What you likely want is a computer algebra system, which understands formulas as artifacts to be manipulated by explicit mathematics rules.

Mathematica和Macsyma是执行此操作的应用程序.但是,这些系统非常复杂,很难看到它们是如何工作的.

Mathematica and Macsyma are applications which do this. However, these are quite sophisticated systems and it is not easy to see how they "work".

您需要做的是:

  • 将公式表示为抽象语法树
  • 将文本公式(您的示例方程式)解析为此类树
  • 编码一组表示代数运算的树操作规则
  • 将这些规则应用于您的代数树
  • 完成后将代数树漂亮地打印回文本中

规则最好用代数的表面语法编写. (Mathematica不会这样做;它使用一种前缀S表达式将公式表示为树,而将规则表示为具有特殊变量节点的同类树).

Rules are best written in the surface syntax of algebra. (Mathematica doesn't do this; it represents formulas as trees using a kind of prefix S-expressions, and rules as the same kind of trees with special variable nodes).

问题之一是要确定要编码多少个代数"规则.数学不仅是纯粹的9年级代数,而且使用这种系统的人们倾向于通过增加更多的知识来扩展那里的内容(Mathematica和Macsyma的观点:它们是无限可扩展的.)

One of the issues is deciding how many "algebra" rules you are wiling to encode. Mathematics is a lot more than pure 9th grade algebra, and people using such systems tend to want to extend what is there by adding more knowledge (the point of Mathematica and Macsyma: they are infinitely extendable).

这是一个非常简单的版本.您可以通过解析树和重写规则来查看所有的齿轮"以及如何描述事物.

Here's a very simple version of this. You can see all the "gears" and how things are described, in terms of parse trees and rewrite rules.

http://www.semdesigns.com/products/DMS/SimpleDMSmainExample.html

这篇关于表达式简化算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆