# math question

This is a discussion on math question within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I am researching loop fusion at my university, but i just started and am confused about the notation for his ...

1. ## math question

I am researching loop fusion at my university, but i just started and am confused about the notation for his summations.
Code:
```            10
w[k] = sum (a[i,j] * b[j,k,l] * c[k,l]
i,j,l```
the i,j,l are what is underneath the sum and their upper bounds are each 10

shouldn't it be
Code:
```for(i=0;i<10;i++){
for(j=0;j<10;j++){
for(l=0;l<10;l++){
w[k] = w[k] + a[i,j] * b[j,k,l] * c[k,l]
}
}
}```
but he does these steps
Code:
```tmp[j] = sum(a[i,j])
i
tmp2[j,k,l] = b[j,k,l] * c[k,l]
tmp3[j,k] = sum(tmp2[j,k,l])
l
tmp4[j,k] = tmp[j]*tmp3[j,k]
w[k] = sum(tmp4[j,k])
j```
i'm confused!

2. I'm not really follwing what you're saying you professor does. I think you'd need an image or something for me to understand.

3. He's just using the distributive property.

Code:
```w[k] = sum_j(tmp4[j,k])
= sum_j(tmp[j]*tmp3[j,k])
= sum_j(sum_i(a[i,j]) * sum_l(tmp2[j,k,l]))
= sum_j(sum_i(a[i,j] * sum_l(tmp2[j,k,l])))    -- using distributive property
= sum_j(sum_i(a[i,j] * sum_l(b[j,k,l] * c[k,l])))
= sum_j(sum_i(sum_l(a[i,j] * b[j,k,l] * c[k,l])))  -- using distributive property.```

4. I'm still confused. Why isn't it like the code. And could you help me write his into code? Like why are you summing over j first and not l?

5. Why would you care that I'm summing over j on the outside and i on the inside? There's no difference.

"Why isn't it like the code?"? What code, yours? I'm not writing code.