如何简化算术表达式包括未知符号 [英] how to simplify an arithmetic expression includes unknown symbol

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

问题描述

我想使用c / c ++来简化算术表达式,但它包含未知符号;

等:



(3 * x + 2 * y)* 2 + x + 3结果将是:7 * x + 4 * y + 3



寻求帮助



谢谢你

解决方案

我认为你真的不明白它:你想要的是什么叫计算机代数系统(CAS)。请参阅:

http://en.wikipedia.org/wiki/Computer_algebra_system [< a href =http://en.wikipedia.org/wiki/Computer_algebra_systemtarget =_ blanktitle =New Window> ^ ]。



目前,我不知道可以嵌入到C ++中的CAS库。此外,我认为你对问题的表述没有任何好处。成像你有可能执行符号字符串计算,但你打算用它做什么?要以一种合理的方式使用它,你最终需要将它编译为C ++表达式,但是如何? C ++并不是一个真正的自我编译系统(但我知道一些天真的人认为它是,我不会责怪他们)。



这不是多么真实CAS系统工作。基本上,它们通常基于 Expression Trees

http:// en .wikipedia.org / wiki / Expression_tree [ ^ ] 。



现在,如果你读到这个,你可以得到一些想法。如果您要用C ++实现自己的CAS库并提供合理的方法来使用它,那就太棒了。这是一个非常可行的问题,但它需要做很多工作。



祝你好运,

-SA


如果你说'x'和'y'是未知数,那么你所拥有的是一个描述线性图的表达式。传统上你会为y求解,然后在某个范围内绘制y与x的关系。解决y,你会得到



y = - (7 * x + 3)/ 4



- [30] -

I want to use c/c++ to simplify an arithmetic expression but it includes unknown symbol;
etc:

(3*x+2*y)*2+x+3 the result will be:7*x+4*y+3

looking for help

thank you

解决方案

I don't think you really understand it: what you want is called Computer Algebra System (CAS). Please see:
http://en.wikipedia.org/wiki/Computer_algebra_system[^].

At this time, I don't know a CAS library which can be embedded into C++. Besides, I don't think your formulation of the problem is any good. Imaging you got the possibility to perform the symbolic string calculations, but what are you going to do with it? To use it in some sensible way, you would ultimately need to compile it as a C++ expression, but how? C++ is not really a self-compiling system (but I knew some naive people who thought it is, and I would not blame them).

This is not how real CAS systems work. Basically, they are generally based on Expression Trees:
http://en.wikipedia.org/wiki/Expression_tree[^].

Now, if you read this, you can get some ideas. If you are going to implement your own CAS library in C++ and offer the reasonable ways to use it, it would be great. This is quite a feasible problem, but it would require a lot of work.

Good luck,
—SA


If you are saying that 'x' and 'y' are unknowns, then what you have is an expression that describes a linear plot. Traditionally you would solve for y, then plot y vs x for some range. Solving for y, you would get

y = -(7*x + 3)/4

-[30]-


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

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