Measure preserving transformation that makes two partitions independent I am looking for a reference for the following result.  I think it is well known but I haven't seen it written down anywhere.
Let $(X, \mathcal{B}, \mu)$ be a standard measure space and let $\mathcal{P}, \mathcal{P'}$ be two finite measurable partitions of $X$.  Then there is a map $\varphi: X \to X$ which preserves the measure $\mu$ and such that the partitions $\mathcal{P}$ and $\varphi^{-1}\mathcal{P'}$ are independent with respect to $\mu$.
(Two partitions $\mathcal{P}$ and $\mathcal{Q}$ are independent with respect to $\mu$ if for any two cells $A \in \mathcal{P}$, $B \in \mathcal{Q}$, $\mu(A \cap B) = \mu(A)\mu(B)$.)
 A: The property does not hold if the measure $\mu$ is atomic, so we  assume that the given standard probability space   $(X, \mathcal{B}, \mu)$  is  nonatomic, whence it is isomorphic to he unit interval. Thus we may assume that $(X, \mathcal{B}, \mu)$ is the unit interval, endowed with the Lebesgue  $\sigma$-algebra and measure. Let $\mathcal{P}=\{A_1,\ldots,A_n\}$ and $\mathcal{P'}=\{B_1,\ldots,B_m\}$. Denote $a_i:=\mu(A_i)$ for $i=1,\ldots, n$ and $s_k:=\sum_{i=1}^k a_i$ for $k=1,\ldots,n$.  Now each $A_k$ is a standard measure space  when endowed with the restrictions of the Lebesgue $\sigma$-algebra and of $\mu$   (see [1]). Thus, there exists a measure preserving transformation   $f:[0,1] \to [0,1]$ such that $f^{-1}[s_{k-1}, s_k)=A_k$ up to measure zero. More precisely,  $f:[0,1] \to [0,1]$  may be defined by
$$\forall k \in\{1,\ldots n\}, \quad \forall x \in A_k, \quad f(x)=s_{k-1}+\mu\Bigl(A_k \cap [0,x] \Bigr) \,.$$
Next, define $\psi:[0,1) \to [0,1]$
$$\forall k \in\{1,\ldots n\}, \quad \forall x\in [s_{k-1},s_k), \quad
 \psi(x)= (x-s_{k-1})/a_k \,.
$$
Observe that $\psi$ preserves Lebesgue measure.
Finally, define
$\varphi: [0,1] \to [0,1]$  by $\varphi:=\psi \circ f$. Then $\varphi$   preserves Lebesgue measure $\mu$,  and   the partitions $\mathcal{P}$ and $\varphi^{-1}\mathcal{P'}$ are independent with respect to $\mu$.
Some further details: The isomorphism  $f$   converts $\mathcal P$ into a partitions into intervals. Then $\psi$ is a piecewise  affine map, taking each interval $f(A_k)=[s_{k-1,}s_k]$ onto $[0,1]$, so for each $B_j \in \mathcal P'$, the preimage $\psi^{-1}(B_j)\cap [s_{k-1,}s_k]$ is a copy of $B_j$, translated and shrunk by a factor of $a_k$. This yields the required independence.
[1] Bogachev, Measure Theory, Vol 2, Springer, Proposition 9.4.10 page 284  https://diendantoanhoc.org/index.php?app=core&module=attach&section=attach&attach_id=12513
A: Here is a variant of the answer by Yuval Peres.  His answer has the advantage that the same map $\varphi$ works for any choice of $\mathcal{P}'$ (the map $\varphi$ erases the information about $\mathcal{P}$).  The variant below has the advantage that the $\varphi$ it provides is bijective.
Suppose $\mathcal{P}=\{A_1,A_2,\ldots,A_n\}$ and $\mathcal{P}'=\{B_1,B_2,\ldots,B_n\}$.
Following Yuval's answer, there exist:

*

*An isomorphism $f\colon X\to[0,1)$ and $0=s_0\leq s_1\leq \cdots \leq s_n\leq 1$ such that $f^{-1}[s_{i-1},s_i)=A_i$ (modulo null sets) for $i=1,2,\ldots,n$.

*An isomorphism $g\colon X\to[0,1)$ and $0=t_0\leq t_1\leq \cdots \leq t_m\leq 1$ such that $g^{-1}[t_{j-1},t_j)=B_j$ (modulo null sets) for $j=1,2,\ldots,m$.

(Note: To be clear, an isomorphism refers to a measure-preserving bijective bi-measurable $f\colon X_0\to I_0$ where $X_0\subseteq X$ and $I_0\subseteq[0,1)$ are measurable, and $X\setminus X_0$ and $[0,1)\setminus I_0$ are null sets.)
Let $Q$ and $Q'$ be the partitions of $[0,1)$ given by $(s_i)_i$ and $(t_j)_j$ respectively.  There exists an isomorphism $\beta:[0,1)\to[0,1)$ such that $Q$ and $\beta^{-1}Q'$ are independent.

The construction is based on the standard method of sampling two independent random variables with prescribed discrete distributions using a single uniformly distributed random number from $[0,1)$.
Namely, consider the two partitions
$Q_0:=\big(s_{i-1}+(s_i-s_{i-1})t_{j-1}\big)_{i,j}$ and
$Q'_0:=\big(t_{j-1}+(t_j-t_{j-1})s_{i-1}\big)_{i,j}$.  Note that $Q_0$
is a refinement of $Q$, and  $Q'_0$ is a refinement of $Q'$.
Furthermore,

*

*There is a natural one-to-one correspondence between the blocks of $Q_0$ and $Q'_0$.  Namely, \begin{gather}   
 \big(s_{i-1}+(s_i-s_{i-1})t_{j-1},s_{i-1}+(s_i-s_{i-1})t_j\big) \\   
 \updownarrow\\    \big(t_{j-1}+(t_j-t_{j-1})s_{i-1},
 t_{j-1}+(t_j-t_{j-1})s_i\big) \end{gather} Note that these two parts
have the same measure $(s_i-s_{i-1})(t_j-t_{j-1})$.

It is easy to use the latter one-to-one correspondence to construct an
isomorphism $\beta$ with the desired property.

Define $\varphi:X\to X$ as $\varphi:=g^{-1}\circ\beta\circ f$.
