I'm trying to write a mathematical notation for the following logic

total = 0
Co = 10

for element in elementlist:
    if element contains A:
        Ci = A
    elif element contains B:
        Ci = B
        Ci = Po
    total += Co - Ci

Here is what I have come up with but I'd like some extra eyes.

enter image description here

Thanks so much!

  • $\begingroup$ One thing you can do is separate out $(n+1)C_0$, then deal with the subtracting the rest, perhaps as three separate sums over $A$, $B$ and $C$. $\endgroup$ Oct 11, 2016 at 17:05
  • $\begingroup$ Could you explain that a bit more - although I'm not sure that's what I'm after? $\endgroup$
    – rh0dium
    Oct 11, 2016 at 17:09
  • $\begingroup$ Your computer code total += Co - Ci sums $n+1$ instances of $C_0$ (once for each time through the loop) and subtracts some values that happen to occur in one of the three lists. If that's not what you're after then you will have to explain it a bit more - I can't. $\endgroup$ Oct 11, 2016 at 17:13
  • $\begingroup$ Think of this calculating total (time) for all of the elements in a list. Co is the End Time (for example right now). Ci is the Start Time. If the element contains A then use A as Ci otherwise B etc. Once you determine Ci add Co-Ci to the total. In english take the end time - start time and add it to the total time $\endgroup$
    – rh0dium
    Oct 11, 2016 at 17:17

1 Answer 1


$$total = \sum_{i\in A}\left( C_0-C_i\right)+ \sum_{i\in B}\left( C_0-C_i\right)+ \sum_{i\in C}\left( C_0-C_i\right)$$ $$ = C_0|A|-\sum_{i\in A}C_i+ C_0|B|-\sum_{i\in B}C_i+ C_0|C|-\sum_{i\in C}C_i$$ $$ = C_0|A|+ C_0|B|+ C_0|C|-\sum_{i\in A}C_i-\sum_{i\in B}C_i-\sum_{i\in C}C_i$$ $$ = C_0\left(|A|+ |B|+ |C|\right)-\left(\sum_{i\in A}C_i+\sum_{i\in B}C_i+\sum_{i\in C}C_i\right)$$ $$ = C_0\left(|A|+ |B|+ |C|\right)-\sum_{i\in A\cup B\cup C}C_i$$

  • $\begingroup$ This is great! Thanks so much - so easy to follow along. Thanks! $\endgroup$
    – rh0dium
    Oct 11, 2016 at 20:19
  • $\begingroup$ May I please ask you to explain in words the last statement. C_o times the vectors of A, B, C or Absolutes? $\endgroup$
    – rh0dium
    Oct 13, 2016 at 13:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .