Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wish to simplify a sum by doing "simplify sum_{a=0}^L f(a)" where $f(a)$ is just some arbitrary expression, but I want to only do the sum when some condition is met.

Using the Iverson brackets, I am trying to do "simplify sum_{a=0}^L [some condition] f(a)" if that makes sense.

share|cite|improve this question
up vote 1 down vote accepted

You might be able use boole, which returns $0$ or $1$ depending on whether it's argument is True or False. Thus, for $n=10$, Euler's phi function $\varphi(n)$ (which counts the number of positive integers less than and relatively prime to $n$) can be expressed as

sum boole(gcd(i,10)=1), i=1..10

enter image description here

Of course, it's hard to say for sure, since you don't mention your specific application. This method of computing $\varphi(n)$, however, happens to be Wikipedia's first example application of Iverson brackets.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.