Leibniz law says $a = b \implies f(a) = f(b)$. Unfortunately this law seems to fail for rational numbers e.g. ${1 \over 2} = {2 \over 4}$ but $numerator({1 \over 2}) \neq numerator({2 \over 4})$. I know that you can say $1 \over 2$ is just representation of "true" rational number and equality we use is just equivalence relation not real equality but this representation is how we think about rational numbers and how we define them in abstract algebra.
Question is: Is there some logically precise (e.g. first order logic) and "true" definition of natural number that respects Leibniz law and makes ${1 \over 2}$ and ${2 \over 4}$ truly equal not just equivalent.
Edit:
To rephrase the question: how do I define rational numbers to avoid problems with representation. In other words is there some axiomatic definition of rationals. Up to this point I've only seen algebraic definitions with pairs and equivalence classes.
You are confusing the object with its various names.
As an object, $\frac12=\frac24$. But you can present it differently. More specifically, in order for the numerator function to be well-defined, you need to choose a representation for each rational first.
Similarly, $1+1=2$, but the length of these two expressions is different. Names are syntax, objects are semantics. Leibniz's law is about semantics, not syntax.