
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!

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.

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.

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?

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.