Can somebody explain this Ray Tracing Function?
Good answer above.    (I like that the book adds in p then subtracts it.)

This is a hard-coded grey world as a "hello world" kind of ray tracer.   The 0.5 is the hard-coded reflectance.   Keep working through book and the object reflectance and max-recursion will be addressed.   Ray branching I avoid like the plague.   In cost benefit I am always a skeptic on ray trees versus ray paths.