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

  • Topic: Mathematica 
  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
  • Tags Tags
    Mathematica
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
2 replies · 4K views
Science Advisor
Gold Member
Messages
4,662
Reaction score
372
I want to write down summation of the type
[tex]\sum_{d|n , d<n}[/tex] or [tex]\sum_{d|n}[/tex] 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