I am trying to construct a lambda expression which works in the following way: assume you have a function $f$ and an argument $x$. The lambda expression I'm trying to build is of the form $P f x$ and evaluates to $P f f(x)$. It would then endlessly evaluates to $P f f^n(x)$ for $n \in \mathbb{N}$ (the infinite loop is not a problem for me).
The lambda expression I have found so far uses the following expression for $P$:
$P=(\lambda g.\lambda f.\lambda x.((g g) f) (f x)) (\lambda g.\lambda f.\lambda x.((g g) f) (f x))$
The problem I'm having is that whereas it seems to me that this should work in theory, passing it to an actual lambda-calculus interpreter either gets me an infinite loop of developing $P$ without $f(x),f^2(x),...$ being evaluated, or I get an infinite loop of expressions with $f(f(f(....(f x))))$ expressions but never the actual value $f^n(x)$, depending on the evaluation method.
Therefore I'm asking here if my solution is sound and it is only a problem of lambda-calculus interpreters, or if there is a better solution to this problem.