TITLE: Prove a function is primitive recursive
QUESTION [6 upvotes]: Hey,
I'm taking a course in computability theory, but I'm struggling with primitive recursion. More specifically we are often asked to prove that some arbitrary function is primitive recursive, but I really don't know how to go about doing so.
For example:
Let $\pi (x)$ be the number of primes that are $\le x$. Show that $\pi (x)$ is primitive recursive.
How do you go about proving this formally? And, in general, what are the necessary conditions to prove if something is or is not primitive recursive.
Note: this isn't homework, I've pulled the question out from a list of examples we have been given :)

REPLY [3 votes]: There is a theorem that says that any function computable on a Turing machine in time that is a primitive recursive function of the length of the input is primitively recursive.
This just mentioned result is a really powerful theorem with numerous applications.
It easily yields results like this one.
Assume g,h,p are prim rec. Then f is prim rec where
f(x,y)=g(x,y) if x times y is 0 and
f(x+1,y+1)=h(x,y,f(x,f(x,p(x,y))),f(x+1,y)).
Trying to figure out "direct solutions" is more or less impossible.
So my recommendation: If course of values recursion and simultaneous
recursion don't work try the theorem above.