3
$\begingroup$

i would like to sum n=0 to n=(some value) over all integers except those that are generated by some function with integer inputs and outputs, like f[n]=(n^2+3n)/2

so it would sum when n=0, n=1, skip n=2, n=3, n=4, skip n=5 ...

the best I've been able to do so far is make a range for both values, then delete my special cases from the first list, but I feel there is a better, more mathematical way to do this so i can start playing with limits and other fun stuff.

$\endgroup$
1
  • 1
    $\begingroup$ Is the resulting list such that you can write a function that gives the $i$-th value? $\endgroup$
    – JimB
    Commented Jan 10, 2023 at 18:40

3 Answers 3

2
$\begingroup$

The comment that you want to sum a convergent function over this domain suggests a different approach. First, an example. Say you want to sum

g[n_] := 1/n^2; 

over the domain of f[n] for all n. This can be done

Sum[g[f[n]], {n, 1, Infinity}]

If you want to sum over the complement of the f[n], then:

f[n_] := (n^2 + 3 n)/2;
g[n_] := 1/n^2; 
Sum[g[n], {n, 1, Infinity}] - Sum[g[f[n]], {n, 1, Infinity}]

Your suggested convergent function 1/10^n can be summed over the complementary domain like this:

f1[n_] := n^2/2;
f2[n_] := 3/2 n;
g[n_] := 1/10^n; 
Sum[g[n], {n, 1, Infinity}] - Sum[g[f1[n]], {n, 1, Infinity}] - 
       Sum[g[f2[n]], {n, 1, Infinity}]

Your answer is in terms of the EllipticTheta function.

$\endgroup$
1
  • $\begingroup$ Thank you, this is exactly what i was looking for! $\endgroup$
    – Wombles
    Commented Jan 17, 2023 at 17:53
3
$\begingroup$

One approach is to define your function f

f[n_] := (n^2 + 3 n)/2;

Then

n = 10;
Complement[Range[n], f /@ Range[n]]

gives the set of elements that you want to sum over. Hence, you can sum them using:

Sum[i, {i, Complement[Range[n], f /@ Range[n]]}]
$\endgroup$
3
  • $\begingroup$ Is it possible to take the limit as this goes to infinity? $\endgroup$
    – Wombles
    Commented Jan 12, 2023 at 17:45
  • $\begingroup$ The limit of the sum would be infinite, no? $\endgroup$
    – bill s
    Commented Jan 12, 2023 at 23:15
  • $\begingroup$ well, i want to sum a convergent series over this domain, something like 1/10^(n) $\endgroup$
    – Wombles
    Commented Jan 13, 2023 at 18:01
3
$\begingroup$
Clear[cSum, k, n]
f[n_] := (n^2 + 3 n)/2;
cSum[k_] := 
 Plus @@ Extract[Range[k], 
   Position[(Solve[f[n] == #, n, PositiveIntegers] & /@ 
      Range[k] ), {}]]

cSum /@ Range[100]

$$\{1,1,4,8,8,14,21,29,29,39,50,62,75,75,90,106,123,141,160,160,181,203,226,250,275,301,301,329,358,388,419,451,484,518,518,554,591,629,668,708,749,791,834,834,879,925,972,1020,1069,1119,1170,1222,1275,1275,1330,1386,1443,1501,1560,1620,1681,1743,1806,1870,1870,1936,2003,2071,2140,2210,2281,2353,2426,2500,2575,2651,2651,2729,2808,2888,2969,3051,3134,3218,3303,3389,3476,3564,3653,3653,3744,3836,3929,4023,4118,4214,4311,4409,4508,4608\}$$

$\endgroup$

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.