1
$\begingroup$

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] $$

$\endgroup$
  • $\begingroup$ Tuples? $\endgroup$ – kglr May 28 '18 at 1:15
  • $\begingroup$ @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. $\endgroup$ – dantopa May 28 '18 at 3:09
3
$\begingroup$
p1 = Array[Subscript[x, #] &, {2}];
p2 = Array[Subscript[y, #] &, {3}];
p3 = Array[Subscript[z, #] &, {2}];
p4 = Array[Subscript[t, #] &, {2}];
Tuples[{p1, p2, p3, p4}] // MatrixForm // TeXForm

$\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)$

$\endgroup$
  • $\begingroup$ ... just hope that $n>10^6$ is a typo:) $\endgroup$ – kglr May 28 '18 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.