I would like to simplify (automatically...) a sum containing constant terms, as in the trivial one:
Sum((A*x[i]+B)^2, i = 1 .. n) = A^2*(sum(x[i]^2, i = 1 .. n))+2*A*B*(sum(x[i], i = 1 .. n))+n*B^2
I can reach this result easily enough by:
- Using the "student" package
- Then expressing the sum underits inert form (Sum(...))
- Expanding it
- Taking its value.
Now the "student" package is "deprecated".... How can I do this without it?
sum to Sum
In one line
S:=Sum((A*x[i]+B)^2, i = 1 .. n); n ----- \ 2 S := ) (A x[i] + B) / ----- i = 1 value(expand(map(op(0..-1,expand(S))))); / n \ / n \ |----- | |----- | 2 | \ 2| | \ | 2 A | ) x[i] | + 2 A B | ) x[i]| + n B | / | | / | |----- | |----- | \i = 1 / \i = 1 /Alec
One line maybe, but cryptic to me...
Thank you...
There is no doubt it works, however that was not exactly the question....
The fact is that the "deprecated student" package allows performing this simplification automatically - which seems logical, since the case indeed trivial....
There is no doubt that one can reach the solution by operand manipulation, and there is no doubt that you have found a very clever way to do that. But to find this solution requires - at least to me...- a fair amount of thinking, which is precisely what I would like to avoid in such a case - why should I dive deep into the differences between Sum and sum, and into the idiosyncrasies of op and map, just to factor the constant terms out of a basic sum?
So I shall reformulate my question: is is possible to have Maple automatically simplfying such expressions without resorting to the "student" deprecated package? If not, why was this behaviour "deprecated"?
why should I dive deep?
No, it should not be necesary to perform low level data structure gymnastics to make such a normal mathematical manipulation. In particular, what is missing here is a package "SumationTools", along the line of the package 'IntegrationTools', with some facilities eg. to distribute the sumation, split its range, combine terms, etc.
SumTools and Summand
There is a SumTools package (which is quite good, by the way - I would say _unusually_ good), but it goes in the different direction than IntegrationTools. The Student:-Calculus1 package has Summand command which shows that it was planned originally to include Sum problems in the Step-by-Step procedures with Rule and Hint, analogous to Int. However, that was not done, and Summand stands alone there without much of use.
The problem here, I think, is not in student or Student packages, but in expand. It should work for sums the same way as it works for integrals - then it could be done as in Axel Vogt's posts in this thread.
Alec
expand vs Expand
The top level 'expand' does not work the same as 'IntegrationTools:-Expand' with respect to linear combinations:
with(IntegrationTools): v := Int(s*f(x)+t*g(x), x = a..b); Expand(v); b b / / | | s | f(x) dx + t | g(x) dx | | / / a a whileexpand(v); b / | | s f(x) + t g(x) dx | / aindefinite case
I meant the case of indefinite integrals,
v := Int(s*f(x)+t*g(x), x); / | v := | s f(x) + t g(x) dx | / expand(v); / / | | s | f(x) dx + t | g(x) dx | | / /Actually, that may be wrong for integrals, if f(x) and/or g(x) are not integrable, so that, maybe, shouldn't work like that, in general. The same for infinite sums - such expanding also may be wrong. There seem to be no such a problem for finite sums.
Alec
IntegrationTools:-Expand
Alejandro,
That, by the way, gives another way of doing that, not so cryptic as with map and op,
S:=Sum((A*x[i]+B)^2, i = 1 .. n): eval(IntegrationTools:-Expand(eval(S,Sum=Int)),Int=sum); / n \ / n \ |----- | |----- | 2 | \ 2| | \ | 2 A | ) x[i] | + 2 A B | ) x[i]| + n B | / | | / | |----- | |----- | \i = 1 / \i = 1 /Alec
level of crypticness
I will leave Paul to evaluate it...
For me, the problem with such low-level tricks, is that they are distracting. Ie they oblige to shift the attention away from Mathematics to Maple data structures. What both ways show is that for such a common operation a 'SummationTool:-Expand' command is missing and should be available (or something that works for integrals and sums).
How long would it take to any of those gifted developers of Maplesoft to provide a "SummationTool" package with some six commands equivalent to 'IntegrationTools'?
(my guess is a few hours at most).
An interesting example of expanding of integrals and sums
While
expand(Int(f(x)-g(x),x)); / / | | | f(x) dx - | g(x) dx | | / /it is interesting that
expand(Int(1/(x-1)-1/x,x)); / | 1 | --------- dx | (x - 1) x /In what sense that may be called expanding?
It works similarly for sums,
expand(Sum(1/(x-1)-1/x,x=2..n)); n ----- \ 1 ) --------- / (x - 1) x ----- x = 2Alec
This is for the wiki
I observe:
`expand/Int`(1/(x-1)-1/x,x); / | 1 | --------- dx | (x - 1) x / showstat(`expand/Int`,1); `expand/Int` := proc(f, r::{name, name = range}) local e, x, inx, notinx, z, c, s, opts, J; 1 e := normal(f); ...I have not tracked it in detail, but may be this 'normal'.
PS. Interesting:
with(student): `expand/Int`(1/(x-1)-1/x,x); / / | 1 | | ----- dx - | 1/x dx | x - 1 | / /Now 'showstat(`expand/Int`)' shows a quite different code.
of course it works
It does?
In every version of Maple I've tried, Axel's code gives
apologies
your reply made me check my ini file ... I load 'student' ... sorry - without it does not heal the problem
without "loading" student
`student/expand/Sum`((A*x[i]+B)^2,i=1..n); / n \ / n \ / n \ |----- | |----- | |----- | 2 | \ 2| | \ | 2 | \ | A | ) x[i] | + 2 A B | ) x[i]| + B | ) 1| | / | | / | | / | |----- | |----- | |----- | \i = 1 / \i = 1 / \i = 1 /Apparently, the code of 'student/expand/Sum' works independently of whether the 'student' package exists or not
student vs. Student
As far as I understand, the original idea was to create Student package with the same functionality as it was in student.
However, the original developer of the first functions in Student package left Maplesoft, and the development was continued by other people, with other design ideas.
As a result, not all of functionality of student package exists in the Student package, and some functions implemented there work in the opposite way to other Maple functions. For example, Student:-LinearAlgebra:-RotationMatrix rotates in the opposite direction to plottools[rotate].
Alec