Mathematica How can I use Mathematica to perform sums with the condition of divisibility?

  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
  • Tags Tags
    Mathematica
AI Thread Summary
To sum over divisors of n, specifically for the expressions ∑_{d|n, d<n} or ∑_{d|n}, the key is to define the summation term as a function of d and n, ensuring that the term evaluates to zero unless d divides n. This can be achieved using conditional statements within the summation. For instance, using the command Sum[If[Mod[n,d]==0,a^d,0],{d,n-1}] allows for the calculation of the sum only for those d that are divisors of n. An example with n=12 yields the result a + a^2 + a^3 + a^4 + a^6, demonstrating the effective use of modulus arithmetic to filter divisors in the summation.
MathematicalPhysicist
Science Advisor
Gold Member
Messages
4,662
Reaction score
372
I want to write down summation of the type
\sum_{d|n , d&lt;n} or \sum_{d|n} both summing over d.
and d|n means d divides n.

I know that I can use Sum[term, {i, n-1}] but I don't know how to use this condition of divisibility to the summation.
any help?

Thanks.
 
Physics news on Phys.org
You need to define term as a function of d and n such that "term = 0 unless d|n." Look into modulus arithmetic commands.
 
In[1]:= n=12; Sum[If[Mod[n,d]==0,a^d,0],{d,n-1}]

Out[1]= a + a^2 + a^3 + a^4 + a^6
 

Similar threads

Replies
4
Views
2K
Replies
6
Views
7K
Replies
0
Views
2K
Replies
1
Views
3K
Back
Top