summation in pari gp

69 Views Asked by At

Is there any command to evaluate in PARI GP such sum: $\sum\limits_{\substack{2\leq d\leq n \\ (d, n)=1}}\frac{a\left(n \right)}{d}$ ? In other words: how to add to command

sum(d=2, n, \frac{a(n)}{d})

condition from second line ($(d,n)=1$).(or more such conditions)

1

There are 1 best solutions below

0
On

There is no built-in way, but it's easy to program. Let's simplify your question to computing $$\sum_{2\leq d \leq n\atop (d,n)=1} a(d) $$ This can be done as follows:

sumcoprime(a, n) = vecsum( [a(d) | d <- [2..n], gcd(n,d)==1] );
? sumcoprime(d -> 1/d, 20)
%1 = 2521693/2909907

? n = 20; S = 0; for (d = 2, n, if (gcd(d,n)==1, S += 1/d)); S
%2 = 2521693/2909907 \\ double check

In many concrete cases, $a(d)$ will be a multiplicative function, and the sum can first be rewritten as a product over primes (less than $n$ and not dividing $n$).