I'm reading http://www.math.mcgill.ca/rags/JAC/124/GodelsProof.pdf
Near the final pages, they prove it.
Here's the proof as I understand it:
All symbols in the language of arithmetic are given a unique Godel number (which is a whole number)
All formulas in arithmetic are also given a unique Godel number by the method: $2^{a}3^{b}5^{c}7^{d}.....$, where 2,3,5,7... are the primes and $a,b,c,d$ are the Godel numbers of the symbols which appear in the formula in the order of their appearance.
Every proof in arithmetic is given a unique Godel number using the same method, except this time $a,b,c,d....$ are the Godel numbers of the formulas which appear in the proof in the order of appearance.
$Dem(x,z)$ is an arithmetic predicate which takes two Godel numbers $x$ and $z$. It is true if the proof corresponding to Godel number $x$ results in the formula (or proves the formula) corresponding to the Godel number $z$.
$sub(y,16,y)$ is an arithmetic function of $y$ (I don't know why two y's are used in the notation). It gives us the Godel number of the formula obtained by replacing all instances of the symbol corresponding to Godel number 16, in the formula corresponding to Godel number $y$, by $y$.
Now we start with the formula:
$$\forall(x), \neg Dem(x,sub(y,16,y))$$
Suppose this formula has Godel number $n$, and $y$ has been assigned Godel number $16$. We substitute $n$ for $y$ to get another formula:
$$\forall(x), \neg Dem(x,sub(n,16,n))$$
By definition of $sub(n,16,n)$, the above formula has Godel number $sub(n,16,n)$, as it has been obtained by replacing $y$ by $n$ in the formula of Godel number $n$
Also, this formula is saying "The formula of Godel number $sub(n,16,n)$ (i.e. the formula itself) is not demonstrable".
Now we prove that this formula is true. We assume that it is false. This means the formula is demonstrable. But that means its negation, which says "The formula is demonstrable", is also demonstrable. Since this is a contradiction, we arrive at the conclusion that the formula is true and undemonstrable. Have I understood this all correctly?
My problem
My problem is with the $Dem$ predicate. Given two Godel numbers $x$ and $z$, how do we calculate the truth value of $Dem(x,z)$?
To do that, we prime factorize $x$, and look at the power of the largest prime factor. If that power is equal to $z$, then that means the formula assigned to $z$ is the last formula (or the final result) in the proof assigned to Godel number $x$. So that means $x$ proves $z$, right?
But this method regards any sequence of formulas, ending in the formula corresponding to Godel number $z$, as a proof of the formula having Godel number $z$. This doesn't take into account any transformation rules of the axioms, whether the proof is logically valid or not. For example, $Dem(z,z)$ would be true by this method and hence every formula would be demonstrable.