If $X\sim \operatorname{Binom}(n,p)$ and $Y\sim \operatorname{Ber}\left(\frac Xn\right)$, then find $E[X\mid Y]$.
Is there a name for such a random variable $Y$, where its distribution depends on another r.v. ?
I got after some lengthy calculation $$P(Y=0)=1-p$$ $$P(Y=1)=p$$
I don't know over which variable to sum ? I must get a function in terms of $Y$
Then $$E[X\mid Y=1]=\sum_\limits{???}\frac{P(X=k)P(Y=1\mid X=k)}{P(Y=1)}$$
what I know, (assuming there are $n$ trials with $n\ge k$)
$$P(X=k)=\binom{n}{k}p^k(1-p)^{n-k}$$
$$P(Y=1\mid X=k)=\frac{k}{n}$$
It is also inappropriate to set $Y=1$ instead of $Y=m$ for some $m$, otherwise I cannot recognize $Y$ in the formula. How to remedy this ?
EDIT: When the variable goes from $k=0$ to $n$ I obtain the following,
$$E[X\mid Y=1]=np-p+1,\quad E[X\mid Y=0]=p(n-1)$$
so it seems legitimate to combine these 2 in the following way,
$$E[X\mid Y]=(np-p+1)Y+\left(p(n-1)\right)(1-Y)$$
Is this true ?
In this answer for convenience $q:=1-p$ and $Z\sim\mathsf{Bin}\left(n-1,p\right)$.
Working out: $$P\left(Y=1\right)=\sum_{k=0}^{n}P\left(Y=1\mid X=k\right)P\left(X=k\right)$$ we find $P\left(Y=1\right)=p$ and consequently $P\left(Y=0\right)=q$.
Then for $k=1,\dots,n$:
$$P\left(X=k\mid Y=1\right)p=P\left(X=k\wedge Y=1\right)=P\left(Y=1\mid X=k\right)P\left(X=k\right)=\frac{k}{n}\binom{n}{k}p^{k}q^{n-k}$$ leading to: $$P\left(X=k\mid Y=1\right)=\binom{n-1}{k-1}p^{k-1}q^{n-k}$$
This reveals that $\left(X-1\mid Y=1\right)\stackrel{d}{=}Z$ so that $$\mathbb{E}\left[X\mid Y=1\right]=1+\mathbb{E}\left[X-1\mid Y=1\right]=1+\mathbb{E}Z=1+\left(n-1\right)p\tag1$$
Similarly we find for $k=0,\dots,n-1$:$$P\left(X=k\mid Y=0\right)q=P\left(X=k\wedge Y=0\right)=P\left(Y=0\mid X=k\right)P\left(X=k\right)=\left(1-\frac{k}{n}\right)\binom{n}{k}p^{k}q^{n-k}$$ so that $$P\left(X=k\mid Y=0\right)=\binom{n-1}{k}p^{k}q^{n-1-k}$$
This reveals that $\left(X\mid Y=0\right)\stackrel{d}{=}Z$ so that $$\mathbb{E}\left[X\mid Y=0\right]=\mathbb{E}Z=\left(n-1\right)p\tag2$$
Based on $(1)$ and $(2)$ we conclude: $$\mathbb{E}\left[X\mid Y\right]=Y+\left(n-1\right)p$$
Edit:
More simple approach that arose later and was inspired by the outcome $\mathbb E[X\mid Y]=Y+(n-1)p$.
Let us set $X=Y+Z$ where $X,Y$ are independent with $Y\sim\mathsf{Bern}\left(p\right)$ and $Z\sim\mathsf{Bin}\left(n-1,p\right)$.
Then observe that $X\sim\mathsf{Bin}\left(n,p\right)$ and that $\left(Y\mid X\right)\sim\mathsf{Bern}\left(\frac{X}{n}\right)$.
This is exactly the situation prescribed in your question except that you stated that $Y\sim\mathsf{Bern}\left(\frac{X}{n}\right)$.
That is actually not correct as Graham Kemp made clear in his answer.
In this situation we find directly: $$\mathbb{E}\left[X\mid Y\right]=\mathbb{E}\left[Y+Z\mid Y\right]=\mathbb{E}\left[Y\mid Y\right]+\mathbb{E}\left[Z\mid Y\right]=Y+\mathbb{E}Z=Y+\left(n-1\right)p$$where the third equality is based on independence.