2 Summations expressed by single loop in programming is possible. Is that possible in Math to do so?

230 Views Asked by At

Suppose there are two summations.

1)$\sum_{i=1}^5a_i = a_1 + a_2 + a_3 + a_4 + a_5 = 2 + 2 + 2 + 2+ 2 = 10$

If $a$ is constant, has value 2.

2) $\sum_{i=1}^5b_i = b_1 + b_2 + b_3 + b_4 + b_5 = 3 + 3 + 3 + 3+ 3 = 15$

If $b$ is constant, has value 3.

Now in programming we can do this.

int a = 0;
int b = 0;
for (int i = 1; i <= 5; i++)
{
    a += 2;
    b += 3;
}

Then at the end of the loop $a = 10$ and $b = 15$. There is no need to write separate loop for both variables.

According my understanding summation behaves as loop. By keeping above programming loop in mind where we can use single loop for 2 different summations because looping condition is same, Is there any way we could do this to summation $\sum_{i=1}^5a_i$ and summation $\sum_{i=1}^5b_i$ by merging them into single summation based on condition. In other words describing 2 different summations by one summation because both summations have same condition.

2

There are 2 best solutions below

2
On BEST ANSWER

Writing the sum $(a,b)$ as an ordered pair, you have

$(a,b)=\sum_{i=1}^5 (a_i,b_i)$

0
On

Another option, in both math and programming, is to declare a function, e.g., $$f(n) = \sum_{i = 1}^5 n = 5n.$$ Then, whenever you need that function, you just "call" it, and you can even nest calls, e.g., $f(f(a) f(b)) + 1$.

At the same time we need to remind ourselves that math and programming are different things.

When publishing a math paper, you want other human beings to understand your mathematical thoughts and deem them elegant; if a computer understands, that's just an added bonus. When publishing the source code of a computer program, you obviously still want other humans to understand your thinking, but the main goal is something that a computer can run in an efficient manner. Even if it's just shaving off a few milliseconds off the benchmark.