He wrote the formula after the first draft but before the huge revisions (more than 75% of the story was deleted) that accompanied the last year or so of the writing process.
Daniel’s math helped a lot with the writing. I needed Daniel to help me understand what variables Colin would care about most. Also, in the process of writing the formula, we came up with lots of jokes (some mathematical and some not) that ended up in the book.
It was really great fun. Mathematicians get a bad rap. All the ones I’ve met are brilliantly funny, Daniel included. (He is now, of course, not so much a mathematician as a politician.)