Informally, I am given a subset $Q$ of a Cartesian product $A_1\times\ldots \times A_n$ and I would like to write $Q$ as a disjoint sum of Cartesian products of subsets of the $A_i$. I would like the decomposition to be optimal in some sense—e.g. the number of terms in the disjoint sum is as small as possible.
Here's a formal statement of the problem:
Given a collection of finite disjoint sets $A_1, \ldots, A_n$ and a subset $Q$ of the Cartesian product $A_1 \times A_2 \times \ldots \times A_n$, find an integer $k$ and subsets $\{ B_{i,j} \subseteq A_j\;: \; i\in [1,k], j\in[1,n]\}$ such that
$$Q \equiv \bigcup_{i=1}^k B_{i,1} \times \ldots B_{i,n} $$
and where $k$ is the smallest integer for which such a decomposition is possible.
I feel like this problem must have been asked before, but I haven't been able to find a solution online, perhaps because I lack the necessary terminology.