Iterating between theory and code

Yesterday I said on Twitter “Time to see whether practice agrees with theory, moving from LaTeX to Python. Wish me luck.” I got a lot of responses to that because it describes the experience of a lot of people. Someone asked if I’d blog about this. The content is confidential, but I’ll talk about the process. It’s a common pattern.

I’m writing code based on a theoretical result in a journal article.

First the program gets absurd results. Theory pinpoints a bug in the code.

Then the code confirms my suspicions of an error in the paper.

The code also uncovers, not an error per se, but an important missing detail in the paper.

Then code and theory differ by about 1%. Uncertain whether this is theoretical approximation error or a subtle bug.

Then try the code for different arguments, ones which theory predicts will have less approximation error, and now code and theory differ by 0.1%.

Then I have more confidence in (my understanding of) the theory and in my code.

5 thoughts on “Iterating between theory and code

  1. This describes my entire Ph.D. work in Computational Chemical Physics – spend weeks writing code, more weeks testing it with toy problems to verify that the code is doing the right thing, more weeks debugging, and then a day to run the actual parameters you want for the real problem.

  2. Let’s say I specilated that this was the journal article you were testing “” . Would you be breaching your confidentiality agreement if you told me it was not that. How much information about a scenario constitutes a breach?

  3. Haven’t seen that article before. But I’ve played out the sequence of events in the blog post many times with little variations on the theme.

  4. A concrete example of, “In theory, theory and practice are the same. In practice, they are not.”


    Having a practice of my own, practically speaking, theory is never practical, but can extend my options, somewhat like my skeleton allows me to extend my reach.

Leave a Reply

Your email address will not be published. Required fields are marked *