# How to express summation over elements of two sets

I have two sets A and B;

$A = \{a_1, a_2, \ldots, a_n\}$

$B = \{b_1, b_2, \ldots, b_k\}$

$n$ and $k$ are different.

My function $f(a, b)$ takes one element of from A and one element from B. And the metric I want to calculate is following:

$Metric_{AB} = f(a_1, b_1) + f(a_1, b_2) + \ldots + f(a_1, b_k) + \ldots + f(a_2 + b_k) + \ldots + f(a_n, b_k)$

Sorry if this is a stupid question, but I can't figure out how to express it as a sum. If $n$ and $k$ were the same, I could have done this:

$$\sum_{n=1}^n f(a_n, b_n)$$ but since these sets are of different size, I'm not sure.

• You're probably looking for $\sum_{i=1}^n \sum_{j=1}^k f(a_i, b_j)$. – Demophilus Oct 27 '17 at 22:58
• the indexes $\sum_{k=a}^n$ is only one possible index. You can have an index be any condition such as $\sum_{b|18}$ would be to add anything that divides $18$. ($\sum_{b|18} b = 1 + 2 +3 +6 +9 +18$ btw). So you can do with $\sum_{a\in A, b\in B}f(a,b)$ will be perfectly acceptable. Now as to how to calculate that ... that's a different story. $\sum_{i= 1}^{n}(\sum_{j= 1}^{k}f(a_i, b_j))$ will do it. You can also do $\sum_{0\le i \le n, 0\le j \le k} f(a_i,b_j)$ – fleablood Oct 28 '17 at 0:57

You can write $$\sum_{x\in A\times B}f(x)$$
The elements of $A\times B$ are the pairs $(a,b)$ with $a\in A$ and $b\in B$.