Let $T$ be a ergodic automorphism of a non-atomic Lebesgue probability space $(X, \mathcal{A}, \mu)$.


The celebrated Rokhlin tower lemma says that given an integer $n>0$ and $0 < \epsilon < 1$, there exists $B \in \mathcal{A}$ such that the sets $B$, $TB$, ..., $T^{n-1} B$ are disjoint and their union (called a *tower* of height $n$) has measure $>1-\epsilon$.


Here's an equivalent formulation of the conclusion of Rokhlin's lemma: the return time function $R\_B \colon B \to \{1,2,\dots, \infty\}$ satisfies:


* $R\_B \ge n$;
* $\int\_B (R\_B - n) d\mu < \epsilon$.


(To see that the integral is the measure of the complement of the Rokhlin tower, thing about the Kakutani skyscraper with base $B$.)



> 
> My question is: Can we replace the constant $n$ above by a function $N$? 
> 
> 
> More precisely: Given an arbitrary measurable function $N : X \to \{1,2,\dots\}$, and $0 < \epsilon < 1$, is there a set $B \in\mathcal{A}$ such that:
> 
> 
> * $R\_B(x) \ge N(x)$ for all $x\in B$;
> * $\int\_B (R\_B - N) d\mu < \epsilon$ ?
> 
> 
> 


Note that the integral is the measure of the *error set* $\{T^i(x) \mid x\in B, N(x) \le i < R\_B(x) \}$.


If $N$ is assumed to be *bounded* then the answer is *yes*. Here's the proof, an easy adaptation of the usual proof of the Rokhlin lemma. Suppose $N$ is bounded by a constant $n$. Take $m > n/\epsilon$. Since the set of periodic points has zero measure, we can take a positive measure set $E$ such that the return time $R\_E$ is $\ge m$. Consider the Kakutani skyscraper with base $E$, which by ergodicity covers a full measure set. For each point $x\_0$ in the base $E$, color blue each of the points $x\_0$, $x\_1:=T^{N(x\_0)}(x\_0)$ (which is at height $N(x\_0)$), $x\_2:=T^{N(x\_1)}(x\_1)$ (which is at height $N(x\_0)+N(x\_1)$), etc., stopping when the height becomes $\ge r\_E(x\_0) - n$ (i.e., when we first reach the floors of the skyscraper $n$-away from the top). Let $B$ be the set of blue points, which is measurable and satisfies $R\_B \ge N$. The error set is contained in the region within height $n$ from the top of the skyscraper, and therefore has measure $<n/m<\epsilon$, as we wanted to show.


I haven't checked, but a similar construction seems to work if the function $N$ is integrable over $X$.



> 
> So the main question is: Is this generalized Rokhlin lemma true for *non-integrable* $N$, or is there a counter-example?
> 
> 
> 


Rem.: Since $R\_B$ is always integrable (Kac's lemma), the restriction of $N$ to $B$ should be integrable.



A Rokhlin lemma with a prescribed height function?
So I've changed my mind! I think the answer is "yes". Suppose $X$ and $N$ are given. Let $\epsilon>0$ be given and let $M$ be such that $\mu({x:N(x)>M})<\epsilon$. Now build a Rokhlin tower with height $M/\epsilon$ and error set of size at most $\epsilon/M$. Let $A$ denote the base of the tower (so that $\mu(A)<\epsilon/M$). For each $x\in A$, let $n\_1(x)$ be the least integer (up to $M/\epsilon-M$) such that $N(T^{n\_1(x)}x)\le M$ (or $n\_1(x)=\infty$ if there is no such finite integer). Then let $n\_2(x)$ be the least integer greater than $n\_1(x)+N(T^{n\_1(x)}x)$ (up to $M/\epsilon-M$) such that $N(T^{n\_2(x)})\le M$ etc. For each $x\in A$, let there be $k(x)\ge 0$ finite values of $n\_j(x)$. 


Let $B\_x=\{T^{n\_j(x)}x:j\le k(x)\}$ and let $B=\bigcup\_{x\in A} B\_x$. This is a measurable set. I claim it has the properties that you want. 


Let $F=\{x\colon N(x)>M\}\cup E\cup \bigcup\_{j=1}^{M-1}T^{-j}(E\cup A)$. This set has measure at most $4\epsilon$. Now for $x\in B$, notice that
$$
R\_B(x)-N(x)\le 
\sum\_{j=0}^{R\_B(x)-1}\mathbf 1\_F(T^jx).
$$
In particular, it follows that 
$$
\int\_B (R\_B-N)\,d\mu\le \mu(F)<4\epsilon,
$$
as required.


**COMMENT**: It was pointed out to me by Jairo Bochi, the poser of the question, that it is not necessary to use Rokhlin's lemma in the proof: it suffices to take $A$ to be any set such that $\mu(A\cap T^{-j}A)=0$ for all $1\le j<M/\epsilon$. In an ergodic system, one can find such a set by taking $A\_0$ to be any set of measure less than $\epsilon/M$ and defining $A=A\_0\setminus\bigcup\_{j=1}^{M/\epsilon}T^{-j}A\_0$ (this set is not of measure 0, as otherwise every point of $A\_0$ would return to $A\_0$ within $M/\epsilon$ steps, so that the measure of $A\_0$ would exceed $\epsilon/M$ by ergodicity.) 


