Say I have a function $f=f(x,y)$ where $x,y$ are independent variables.
Now, it is given that $p=x+y$.
It can be shown that, since $x,y$ are independent, we get $$\frac{\partial p}{\partial x}=\frac{\partial x}{\partial x}+\frac{\partial y}{\partial x} \implies \frac{\partial p}{\partial x}=1+0 \implies \frac{\partial x}{\partial p}=1$$ and similarly $$\frac{\partial p}{\partial y}=\frac{\partial x}{\partial y}+\frac{\partial y}{\partial y} \implies \frac{\partial p}{\partial y}=0+1 \implies \frac{\partial y}{\partial p}=1$$
Now I can write that $$\frac{\partial f}{\partial p}=\frac{\partial f}{\partial x}\cdot\frac{\partial x}{\partial p}+\frac{\partial f}{\partial y}\cdot\frac{\partial y}{\partial p}$$ And using the above values, we get that $$\frac{\partial f}{\partial p}=\frac{\partial f}{\partial x}\cdot1+\frac{\partial f}{\partial y}\cdot1=\frac{\partial f}{\partial x}+\frac{\partial f}{\partial y} \tag1$$
So if I replace $f$ by $p$ in $(1)$, which is quite valid since, like $f$, $p$ is also a function in $x,y$, we get that $$\frac{\partial p}{\partial p}=\frac{\partial p}{\partial x}+\frac{\partial p}{\partial y} \implies \large\color{red}{1=2}$$
How is this possible? Where is the error? Can someone point it out for me?
Addendum as per Surb's answer and comments:
If, as Surb concludes, for $x,y$ being independent, $\frac{\partial x}{\partial p}=\frac{\partial y}{\partial p}=0$, so I will get $\frac{\partial f}{\partial p}=0$ for all $f=f(x,y)$. But this is not true at all. How about $f=p^2=(x+y)^2$?
So where is the mistake?
Your mistake is thinking in terms of "dependent" / "independent" symbols without introducing precise mathematical meaning for that.
You can't say that $\frac{\partial p}{\partial x}=1$ implies $\frac{\partial x}{\partial p}=1$. $p$ is a function of two variables $(x,y)$, and to calculate $\frac{\partial x}{\partial p}$, you should introduce another variable, say, $q(x,y)$, such that $(p, q)$ form a coordinate system.
For example, let $q = x-y$. Now $(p,q)$ are a coordinate system, and we can express $x$ and $y$ in terms of them:
$$x=\frac{p+q}{2}$$ $$y=\frac{p-q}{2}$$
So, it now happens that $$\frac{\partial x}{\partial p} = \frac{1}{2} \color{red}{\neq} \left(\frac{\partial p}{\partial x}\right)^{-1}$$
Note that introducing an other coordinate instead of $q$ will affect $\frac{\partial x}{\partial p}$ too, so you can't speak of $\frac{\partial x}{\partial p}$ alone.