For a research project I am working on currently, I need to do a very simple and straightforward calculation. Unfortunately, I do not know how to include Mathematica code here, but it is very short anyway:
b[x_] := x^2 - x + 1/2
bp[x_] := b[Mod[x, 1]]
d[n_, q_] := Sum[bp[k/n]* bp[q*k/n], {k, 0, n - 1}]
Now I need to compare two values of d[n,q], in particular, I need to calculate
d[1346269,514229] and d[1346269,1137064] to see which one is larger. It works perfectly fine for smaller numbers, e.g. I tried d[75025, 28657] and got the correct result in a reasonable amount of time. However, when I tried evaluating d[1346269,514229] after some time I got the result
(1/9760128332100732436)(4744910246749618660646829 -
4880064166050366218 Hold[$ConditionHold[$ConditionHold[
System`Dump`AutoLoad[Hold[Sum`InfiniteSum],
Hold[Sum`InfiniteSum, Sum`SumInfiniteRationalSeries,
Sum`SumInfiniteRationalExponentialSeries,
Sum`SumInfiniteLogarithmicSeries,
Sum`SumInfiniteBernoulliSeries,
Sum`SumInfiniteFibonacciSeries, Sum`SumInfiniteLucasLSeries,
Sum`SumInfiniteArcTangentSeries,
Sum`SumInfiniteArcCotangentSeries,
Sum`SumInfiniteqArcTangentSeries,
Sum`SumInfiniteqArcCotangentSeries,
Sum`SumInfiniteStirlingNumberSeries,
Sum`SumInfiniteqRationalSeries], "Sum`InfiniteSum`"]]]][(1 -
Ceiling[(1 - Sum`FiniteSumDump`l)/1346269] +
Floor[(1346268 - Sum`FiniteSumDump`l)/1346269]) Mod[(
514229 Sum`FiniteSumDump`l)/1346269, 1], {Sum`FiniteSumDump`l,
0, 1346268}, True])
Now, I am not too familiar with Mathematica, so I am not sure where the problem is exactly. However, I would need the two results of d[1346269,1137064] and d[1346269,514229] exactly (i.e. not numerically) as they are super close together, so any rounding could already change the results sufficiently much to alter the order of the two. Is there any way of computing those sums symbolically?
Table[d[n, q], {q, 0, Ceiling[n/2]}]
and then find the smallest element. Is there another way of speeding up the computation of the entire table as well? I thought of first computing
Table[bp[k/n],{k,0,n-1}]
and then just reading the function values from that table. But since bp is not a very complicated function, I was not sure whether this is significantly faster. But is there some way of speeding this up?
– Analysis801 May 10 '19 at 06:09Sin[Range[0, 100, 0.001]]is faster thanTable[Sin[i], {i, 0, 100, 0.001}]which is faster thanFor[i = 0, i <= 100, i = i + 0.001, Sin[i]]. – MassDefect May 10 '19 at 18:03