Here comes two definition of one-way function, the first one comes from wikipedia while the second one is by myself.
I'm curious about whether they are equivalent and have been considering for a long time.
For short, I won't write "easy to compute" part, and focus on "hard to invert".
Deinition 1. A function $f:\{0,1\}^*\rightarrow\{0,1\}^*$ is hard to invert if:
For all probabilistic polynomial time algorithm $A$, and for all polynomial $p(n)$, it holds
$$ \exists N\in\mathbb{N}.\;\text{s.t. }\forall n\geq N.\;\mathop{\text{Prob}}_{x\sim U_n}[f(A(f(x)))=f(x)]\leq\frac{1}{p(n)} $$ where $U_n$ is the uniform distribution over $\{0,1\}^n$.
Definition 2. A function $f:\{0,1\}^*\rightarrow\{0,1\}^*$ is hard to invert if:
For all probabilistic polynomial time algorithm $A$, and for all polynomial $p(n)$, it holds $$ \exists N\in\mathbb{N}.\;\text{s.t. }\forall n\geq N.\;\mathop{\text{Prob}}_{y\sim U_S}[f(A(y))=y]\leq\frac{1}{p(n)} $$ where $U_S$ is the uniform distribution over $S=\{f(x)\mid |x|=n\}$.
Is this two definitions equivalent? Intuitively I think they are not, but if possible please show me an example $f$.
Thanks a lot.