可以用程序来简化代数表达式吗?

发布于 2024-11-29 05:42:15 字数 297 浏览 1 评论 0原文

我们知道1+2+...+n等于n(n+1)/2

但是,如果我们事先不知道的话,我们能通过编程得到相同的结果吗?

关于我为什么会有这样的疑问。

考虑一个更复杂的情况:

X1+X2+...+Xk=n,其中 Xi 是整数且 >= 0。

X1^2+...Xk^2 的期望是什么?

结果乍一看并不明显,一旦我们计算出 X1^2+ 的期望的(详细)数学表示,我们就会将其提供给程序以减少代数... Xk^2

We know 1+2+...+n is equal to n(n+1)/2.

But can we get the same result programatically if we don't know it in advance?

About why I have such a question.

Think of a more complex situation:

X1+X2+...+Xk=n, where Xi is integer and >= 0.

What's the Expectation of X1^2+...Xk^2?

The result is not obvious just by a glance, and we'll want to feed it to a program to reduce the algebra once we've worked out the (verbose)mathematical representation of Expectation of X1^2+...Xk^2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清风夜微凉 2024-12-06 05:42:15

也许您正在考虑计算机代数系统 (CAS)? WolframAlpha 是一款免费的在线软件,其后端使用 Mathematica(一种非常强大的 CAS 系统)。在这里您可以看到它计算/简化您的表达式: WolframAlpha

您的示例只是 平方和,它有一个非常简单的显式公式: n(n+1)(2n+1)/6。更一般地,您可以使用 Faulhaber 公式 来计算 n^p 的总和< /代码>。

Perhaps you're thinking of a Computer algebra system (CAS)? WolframAlpha is a free online one that uses Mathematica (a very powerful CAS system) on it's backend. Here you can see it compute/simplify your expression: WolframAlpha.

Your example is just the sum of squares which has a pretty simple explicit formula: n(n+1)(2n+1)/6. More generally, you can use Faulhaber's formula to calculate Sum of n^p.

红颜悴 2024-12-06 05:42:15

好的,首先是关于问题的数学部分的一些建议,然后是关于软件开发的一些建议。

一本电子书“A=B”,作者:Marko Petkov·sek 、Herbert S. Wilf 和 Doron Zeilberger 处理求和问题的求解(或表明无解)甚至比多项式更困难。 Ia​​n Wanless 对本书的评论值得快速阅读。该电子书可免费下载,但可以购买装订本,例如从亚马逊购买。

2004年跨。 AMS 论文C-有限序列的闭式求和格林和维尔夫 (Greene and Wilf) 的 也可在线获取。

一般来说,你需要一些基本的 CAS 软件来实现这些算法,听起来目标是自己开发这样的软件。我建议学习一些开源 CAS(计算机代数软件)软件包,例如 MaximaAxiom 了解所涉及内容的范围。当然,目标狭窄的应用程序可能只能完成这些相当成熟和高端的软件包所实现的一小部分,但鉴于问题的当前措辞,我不认为我可以为您指出一条更直接的路径。

如果表达式的“期望”包含在您的项目范围内,那么除了单纯的代数运算之外还会出现许多复杂情况。人们当然需要能够指定概率密度函数来支持期望值,并且可能需要一些集成软件(尽管可能限制参数化分布的选择可能会导致查找这些分布矩的简化问题)。我确实认为这是一个特别好的应用程序,因为看似简单的随机变量表达式(总和、最大/最小值)可能会导致对案例的噩梦般的考虑,非常适合计算机的耐心。

Okay, first some suggestions about the math part of the question and then some about the software development.

There's an e-book "A=B" by Marko Petkov·sek, Herbert S. Wilf and Doron Zeilberger which deals with solving (or showing there is no solution of) summation problems even more difficult than just polynomials. A review of the book by Ian Wanless is worth a quick reading. The e-book is freely downloadable, but bound copies can be purchased, e.g. from Amazon.

A 2004 Trans. of AMS paper Closed Form Summation of C-finite Sequences by Greene and Wilf is also available online.

In general you will need some basic CAS software to implement these algorithms, and it sounds like the goal is to develop such software yourself. I would recommend studying some of the open source CAS (computer algebra software) packages like Maxima or Axiom to get a feel for the scope of what is involved. Of course it's likely that a narrowly targeted application can do with only a fraction of what these fairly mature and high-end packages implement, but I don't feel that I can point you down a more directed path given the current phrasing of the question.

If "Expectation" of expressions is included in the scope of your project, there are a number of complications piled on top of mere algebraically manipulation. One certainly needs to be able to specify probability density functions to support expected values, and presumably some integration software (though potentially limiting the choice of parameterized distributions could lead to a simplified problem of looking up moments of those distributions). I do think this is a particularly nice application to jump into, as seemingly simple expressions (sums, max/min) of random variables can lead to nightmarish consideration of cases, well-suited to the patience of a computer.

清欢 2024-12-06 05:42:15

编辑,由于您最近对该帖子的澄清。

除非您拥有一整套由博士组成的团队并花费数年时间,否则您无法摆脱手工制作的解决方案。我能给你的最好建议是购买 Mathematica (或其他)许可并将其与您的程序连接。

如果您是一名 Lisp 程序员,使用 Maxima 是另一种潜在的(免费这个)解决方案。

如果您想了解求和算法的最新技术背景,本文是一个好的开始。


X1+X2+...+Xk=n,其中 Xi 为整数且 >= 0。

X1^2+...Xk^2 的期望是什么?

这类问题占用了很多人去弄清楚如何在纸上做。

让我们取 k = 2。然后 X_1 + X_2 = n 给出 X_2 = n - X_1。

因此,要计算的期望为 E = X_1^2 + (n - X_1)^2 = 2 X_1^2 -2n X_1 + n^2

其内容

E = sum(p_k * (2 * k^2 - 2 * n * k + n^2), k = 0..infinity)

p_k = Prob(X_1 = k)。这种总和取决于p_k,通常很难计算。我想说这个问题比计算封闭形式的积分还要困难(没有软件完全实现可用的但不可判定的 Risch 算法)。

为了说服自己,请采取例如。 p_k = 1 / (log(k) * k^4)

为其找到一个公式(或公式生成器)至少是一个非常困难的研究问题。

EDIT, due to your recent clarification of the post.

You won't get away with a hand made solution, unless you have a whole team of PhDs and several years to spend. The best advice I can give you is to buy a Mathematica (or other) license and interface it with your program.

If you are a Lisp programmer, using Maxima is another potential (free this one) solution.

If you want background on the state of art in summation algorithms, this paper is a good start.


X1+X2+...+Xk=n, where Xi is integer and >= 0.

What's the Expectation of X1^2+...Xk^2?

This kind of problems occupy a lot of people to figure out how to do it on paper.

Let us take k = 2. Then X_1 + X_2 = n gives X_2 = n - X_1.

So the expectation to be computed is E = X_1^2 + (n - X_1)^2 = 2 X_1^2 -2n X_1 + n^2.

This reads

E = sum(p_k * (2 * k^2 - 2 * n * k + n^2), k = 0..infinity)

where p_k = Prob(X_1 = k). This kind of sums, depending on p_k, is generally very difficult to compute. I'd say that the problem is even more difficult than computing integrals in closed form (for which no software fully implement the available -- but undecidable -- Risch algorithm).

To convince yourself, take eg. p_k = 1 / (log(k) * k^4).

Finding a formula (or a formula generator) for it is at the very least a very difficult research problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文