1
$\begingroup$

Suppose that I have a polynomial of order $n$ $$ f_n(k)=\sum_{m=0}^n a_k k^m, $$ where $k$ is an integer and $a_k$ are arbitrary real numbers. Now I want to use Mathemtica to calculate $$ \sum_{k=1}^p f_n(k). $$ Mathematica does it pretty fast even for large $n$.

Q0. How does Mathematica calculate these sums? I'm asking mainly about how the engine processes it. I suppose it takes $k^m$ (one by one $m=0,\dots,n$) and uses some known (analytical) procedures for summing the partial sums over $k$.

Q1. What is the scaling as a function of $n$ for a fixed $p$ Mathematica achieves? Some experimenting shows that is must be polynomial in time.

Q2. Independently on Mathematica, what is the computational complexity of calculating such sums as a function of $n$ (for a fixed $p$)?

EDIT: The coefficients of $k^m$ in $f_n(k)$ are set to one but they are otherwise arbitrary real numbers so $f_n(k)$ can't be in general simplified.

EDIT: I added coefficients $a_k$ to the first sum to make the question more clear.

$\endgroup$
4
  • $\begingroup$ looking at your edit id suggest you provide a concrete example with real coefficients. That changes the question entirely.. $\endgroup$
    – george2079
    Commented Jan 2, 2015 at 19:49
  • $\begingroup$ Are you saying that Mathematica always tries to simplify the first sum before going on? I want to consider the worst-case scenario where nothing can be done to simplify the first sum. $\endgroup$
    – user155002
    Commented Jan 2, 2015 at 20:55
  • $\begingroup$ no I was just saying the potential for analytic simplification changed the problem in a way that isn't relevant to your actual problem. For the general problem I don't think if does anything more interesting than brute force evaluation of all (n+1)*p terms. $\endgroup$
    – george2079
    Commented Jan 2, 2015 at 21:28
  • $\begingroup$ Ok, see my comment in @DumpsterDoofus's answer because this is my Q1. $\endgroup$
    – user155002
    Commented Jan 3, 2015 at 0:39

1 Answer 1

5
$\begingroup$

I have no idea how Mathematica evaluates such sums. However, note that $f_n(k)=\frac{k^{n+1}-1}{k-1}$, meaning that

Q1. What is the scaling as a function of n for a fixed p Mathematica achieves? Some experimenting shows that is must be polynomial in time.

has the answer $O(1)$, provided that you force symbolic evaluation of $f_n(k)$.

Meanwhile, you could also ask what the scaling is as a function of $p$. It's natural to guess polynomial time, which you can verify by the following:

Sum[k^m, {m, 0, n}]
f[p_, n_] = Sum[%, {k, 2, p}]
DiscretePlot[Log[10, #] &@First@Timing@f[Round[10^k], 12], {k, 3, 6, 0.1}]

enter image description here

The slope of the line is 1, indicating linear time, or $O(p)$ execution.

$\endgroup$
6
  • $\begingroup$ Ah, I was being sloppy and forgot to mention that the coefficients of $k^m$ were set to one just for simplicity. They can be arbitrary, please see the edit. $\endgroup$
    – user155002
    Commented Jan 2, 2015 at 19:30
  • $\begingroup$ @user155002: In that case, no simplification is done, and it's probably just going to be $O(np)$ as george2079 said in his comment. $\endgroup$ Commented Jan 2, 2015 at 22:50
  • $\begingroup$ Ok, is it obvious that it is linear in $n$ for a fixed $p$? $\endgroup$
    – user155002
    Commented Jan 3, 2015 at 0:37
  • $\begingroup$ @user155002: For fixed $p$, $O(np)=O(n)$, so yes. I'll edit my answer to include an example illustrating this. $\endgroup$ Commented Jan 3, 2015 at 1:30
  • $\begingroup$ I totally believe that $O(np)=O(n)$ for a fixed $p$ :) My question is does Mathematica achieve that considering the way it actually (symbolically) calculates it? $\endgroup$
    – user155002
    Commented Jan 3, 2015 at 1:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.