Using
f[n_] := Sum[1/(Sqrt[k] + Sqrt[k + 1]), {k, 1, n}]
to analyze the well-know series...
I noticed a sudden performance drop (on my outdated PC hardware ) around n=14.
f[14] // FullSimplify
Is there away to overcome this? Memoization comes to mind.
What would be a method to monitor performance of such a function?
Not sure how to go ahead with this.
Sum[1/(Sqrt[k] + Sqrt[k + 1]), {k, 1, n}]
to give-1 + Sqrt[1 + n]
Additionally, are you sure you're timing the summation itself and notFullSimplify
? The timing results up to n=40 seem reasonable to me. $\endgroup$f[n_] := f[n] = Sum[1/(Sqrt[k] + Sqrt[k + 1]), {k, 1, n}]; f[40]; // RepeatedTiming
I get 4 10^-7 sec what seems rather fast. $\endgroup$FullSimplify
, not fromSum
. You can useRootReduce
instead ofFullSimplify
: the former is more precisely targeted to the task. $\endgroup$Remove["Global`*"]
then tryTotal[Table[1/(Sqrt[k] + Sqrt[k + 1]), {k, n}]]
or do the Sum withMethod->"Procedural"
ignoring theFullSimplify
- you will find that in both cases f[14] is initially very fast, but the second time you run it is much slower. Not sure why but possibly caused by some kind of caching in mathematica's automatic simplification. $\endgroup$