Understanding sum/product algorithms

  • Thread starter Hobold
  • Start date
  • Tags
    Algorithms
In summary: = b[n] b[n-1] ... b[2] b[1] + b[n-1] ... b[2] b[1] + ... + b[2] b[1] + b[1] + 1z = b[n] b[n-1] ... b[2] b[1] + (b[n-1] ... b[2] b[1] + ... + b[2] b[1] + 1) = b[n] b[n-1] ... b[2] b[1] + 1 + z = b[n] b[n-1] ... b[2] b[1] + 1 + b[n
  • #1
Hobold
83
1
Understading sum/product algorthms

Hello there,

I'm having a little trouble understanding sum/product algorithms. I can do single sum/product algorithms, but when it comes to multiple/combined summations or products I just can't follow.

Ex.:

[tex]\sum_{i=0}^n (a_i x + c_i)[/tex]

Ok, this one was pretty simple, I have no problem in doing that. Though when it comes to things like

[tex]\sum_{i=0}^n \left ( \prod_{j=0}^i (a_i x + c_i) \right )[/tex]

it gets hard. I have made a few algorithms, though I have no idea if they are right. I assume you can write using only one loop, but I have no idea how. Here's what I'd write for that one:

Code:
z = 0; y = 1;

for i = 0 to n do

   for j = 0 to i do
      z = z + a[i] * x + c[i];
   end for

   y = y*z;

end for

I can't work the other way around as well. When I notice some algorithm results in combined product/sum notation, I can't write it right, such as

Code:
v = a[0];
z = x;

for i = 1 to n do
   v = v +z*a[0];
   z = x*z;
end for

Could anyone help me understand? Or at least suggest any book or text on these?
 
Technology news on Phys.org
  • #2


The inner loop is a product loop, you should initialize z = 1, and then each step should be z = z * ... or the alternate form z *= ... . The outer loop is a summation, so initialze y = 0, and each step should be y = y + ... or y += ...
 
  • #3


Code:
sum:=0
for i:=0 to n do
	prod=1
	for j:=0 to i do
		prod:= prod * (a[i]*x + c[i])  // i?
	sum:= sum + prod
 
  • #4


Thanks, I got that...

What would

Code:
v = a[0];
z = x;

for i = 1 to n do
   v = v +z*a[0];
   z = x*z;
end for

be in sum/product notation?

I am curretly using "Numerical Mathematics and Computing" by W. Cheney and D. Kincaid. Though it doesn't explain anything about those algorithms, there are some exercises in which the authors ask you to transform from notation -> algorithm and vice-versa. In the answer section, there are answers I cannot interpret such as:

Code:
z = b[n] + 1;

for k = 1 to n-2 do
   z = z*b[n-k] + 1;
end for

stands for [tex]z = 1 + \sum_{i=2}^n \prod_{j=2}^i b_j [/tex]

I have really no idea on how the author got to that answer.
 
  • #5


Hobold said:
I have really no idea on how the author got to that answer.
Try manually writing out the calculated terms for the first few loops, and you'll see why it works. As to how he figured it out, either he's clever or he copied the technique from yet another clever person.

z = b[n] + 1
z = (b[n] + 1) (b[n-1]) + 1 = b[n] b[n-1] + b[n-1] + 1
z = (b[n] b[n-1] + b[n-1] + 1) (b[n-2) + 1 = b[n] b[n-1] b[n-2] + b[n-1] b[n-2] + b[n-2] + 1
z = ...
 
Last edited:

1. What is a sum/product algorithm?

A sum/product algorithm is a mathematical method for finding the sum or product of a series of numbers. It involves breaking down the numbers into smaller parts and then combining them using specific rules or formulas.

2. How do sum/product algorithms work?

Sum/product algorithms work by breaking down a series of numbers into smaller parts and then using specific rules or formulas to combine them. For example, in a sum algorithm, the numbers would be added together, while in a product algorithm, the numbers would be multiplied together.

3. What are some applications of sum/product algorithms?

Sum/product algorithms are commonly used in various areas of mathematics, such as in calculus, statistics, and number theory. They can also be used in computer programming to solve mathematical problems or optimize algorithms.

4. Are there different types of sum/product algorithms?

Yes, there are different types of sum/product algorithms, including iterative algorithms, recursive algorithms, and dynamic programming algorithms. Each type has its own advantages and can be used for different types of problems.

5. How can I improve my understanding of sum/product algorithms?

To improve your understanding of sum/product algorithms, it is helpful to practice solving problems using different algorithms and to understand the underlying principles behind them. You can also consult textbooks, online resources, or seek guidance from a math expert.

Similar threads

  • Programming and Computer Science
Replies
1
Views
956
  • Programming and Computer Science
Replies
9
Views
1K
Replies
9
Views
1K
  • Programming and Computer Science
Replies
25
Views
2K
  • Programming and Computer Science
Replies
4
Views
616
  • Programming and Computer Science
Replies
2
Views
896
  • Programming and Computer Science
Replies
30
Views
4K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
7
Views
1K
Back
Top