Find vertices of a hypercube given a set of partitions

Problem

The goal is to take a set of $n$ linear partitions $\left\{p_{k}\right\}_{k=1}^{n}$ and create a hypercubic partition:

$$\mathbf{P}=p_{1}\times p_{2}\times \cdots\times p_{n}$$

Each partition $p$ has a know length $m_{k}$, ${k=1,n}$.

In practice $n>10^{6}$.

Example:

Input

Let $n=4$ and the partition set consists of $p_1=(x_1,\dots,x_{m_1})$, $p_2=(y_1, \dots, y_{m_2})$, $P_3=(z_1,\dots,z_{m_3})$, and $p_4=(t_1,\dots,t_{m_4})$.

Output

The $\prod_{k=1}^{n}m_{k} \times n$ array containing the vertices of the hypercubic mesh: $$\bf{A} = \left[ \begin{array}{cc} % x_1 & y_1 & z_1 & t_1 \\ % x_1 & y_1 & z_1 & t_2 \\ % x_1 & y_1 & z_1 & \vdots \\ % x_1 & y_1 & z_1 & t_{m_{4}} \\ % x_1 & y_1 & z_2 & t_1 \\ % x_1 & y_1 & z_2 & \vdots \\ % x_1 & y_1 & z_2 & t_{m_{4}} \\ % \vdots & \vdots & \vdots & \vdots \\ % x_{m_{1}} & y_{m_{2}} & z_{m_{3}} & t_{m_{4}} \\ % \end{array} \right]$$

• – kglr May 28 '18 at 1:15
• @kglr. Bingo! $A=$Tuples[$p_1,p_2,p_3,p_4$]. If you submit a formal answer I can mark it as the solution. – dantopa May 28 '18 at 3:09

p1 = Array[Subscript[x, #] &, {2}];

$\left( \begin{array}{cccc} x_1 & y_1 & z_1 & t_1 \\ x_1 & y_1 & z_1 & t_2 \\ x_1 & y_1 & z_2 & t_1 \\ x_1 & y_1 & z_2 & t_2 \\ x_1 & y_2 & z_1 & t_1 \\ x_1 & y_2 & z_1 & t_2 \\ x_1 & y_2 & z_2 & t_1 \\ x_1 & y_2 & z_2 & t_2 \\ x_1 & y_3 & z_1 & t_1 \\ x_1 & y_3 & z_1 & t_2 \\ x_1 & y_3 & z_2 & t_1 \\ x_1 & y_3 & z_2 & t_2 \\ x_2 & y_1 & z_1 & t_1 \\ x_2 & y_1 & z_1 & t_2 \\ x_2 & y_1 & z_2 & t_1 \\ x_2 & y_1 & z_2 & t_2 \\ x_2 & y_2 & z_1 & t_1 \\ x_2 & y_2 & z_1 & t_2 \\ x_2 & y_2 & z_2 & t_1 \\ x_2 & y_2 & z_2 & t_2 \\ x_2 & y_3 & z_1 & t_1 \\ x_2 & y_3 & z_1 & t_2 \\ x_2 & y_3 & z_2 & t_1 \\ x_2 & y_3 & z_2 & t_2 \\ \end{array} \right)$
• ... just hope that $n>10^6$ is a typo:) – kglr May 28 '18 at 7:43