A taxing algorithm

My first encounter with the term algorithm did not come from Don Knuth. I learned it from the Internal Revenue Service. Sometime in the late 1960s or early 70s the IRS introduced a redesigned Form 1040 based on a principle borrowed from the world of computing: the algorithm. What this meant, I soon discovered, was that the wording of the instructions would be procedural rather than declarative. Instead of “Your tax is 15 percent of the amount on line 42,” we had “Multiply the amount on line 42 by 0.15 and write the result on line 43.” I had expected something more revolutionary, but at least I expanded my vocabulary.

I’ve filled out a lot of 1040s since then, but until yesterday I had never become acquainted with Schedule D (Capital Gains and Losses). What a treat I had waiting for me! Tucked inside the Schedule D instruction book, I found a marvel of labyrinthine arithmetic and logic. The tax worksheet on pages D-15 and D-16 might well be the most complex algorithm that ordinary people are ever asked to perform.

Below is my attempt to represent the worksheet as a data-flow diagram. Inputs (mostly dollar amounts copied from elsewhere in the tax return) are in blue; the eventual output (tax owed) is in red; the flow is mostly from bottom to top. The numbers in the boxes correspond to line numbers in the worksheet.

data-flow diagram for IRS Schedule D tax worksheet

The directed graph has 82 nodes and 96 edges. Twelve subtractions, seven additions, four multiplications, ten comparisons, and two table lookups. Now that’s an algorithm! It’s gnarlier than calculating the date of Easter.

What are the chances that I correctly followed all the steps of this algorithm? What are the chances that the published algorithm correctly implements the intent of the tax code?

This entry was posted in computing, modern life.

12 Responses to A taxing algorithm

  1. Rettaw says:

    Considering the last operation in the graph is a comparison, and neither of the operands end up in the output slot, I think its pretty likely you’ve made some mistakes…

    • Brian Hayes says:

      As the legend at the bottom of the chart indicates, that function is \(\min(a, b)\) and either \(a\) or \(b\) ends up in the output.

      But I don’t dispute the likelihood of mistakes. My point in making the chart was to suggest that the IRS might consider some of the later lessons of computer science, having to do with concepts such as modularity and abstraction.

    • Josiah C. says:

      You are likely misreading the diagram, I misread it at first too. The numbers in the boxes are where data is coming from or going to. So for the top left part where you get [45] = min([44], [43]) , you find the minimum of lines 43 and 44, and put that result on line 45.

  2. Greg says:

    Rettaw, I’m fairly sure that’s not a comparison but a minimal element of set of operands.

  3. Hein Hundal says:

    Beautiful Diagram. What software did you use to create it?

    • Brian Hayes says:

      I made two failed attempts with pencil and paper, then produced the drawing you see with Adobe Illustrator. In this day and age it’s a little embarrassing to admit that I do such things by hand, but then I also still file my taxes by carrying a fat envelope to the post office.

      • Sqeaky says:

        Don’t feel embarrassed. Pen and paper have had a few thousand years to get their critical app correct. Nothing digital allows the ease, low cost and free form expression paper currently provides.

        For some things digital means have surpassed paper, like writing books and editing flowcharts, but digital has not surpassed paper in every way.

  4. vzn says:

    without a doubt the tax system is one of the most messed up/ labyrinthine bureaucracies on the planet and shows similarities to decades-old legacy code in IT. you didnt even get into how corps are not taxed effectively, that loopholes worth millions or even billions of dollars exist for corps or wealthly individuals, the irrationality of various (non)taxes etc…. changes over the last few decades decreasing max rates probably contributes massively to wealth inequality…. etc! and years ago prez reagan talked about “tax simplification”…. aieeee!

  5. Todd says:

    I think you have the wrong link for the Schedule D. (There are many schedule D’s.) I think you want http://www.irs.gov/pub/irs-pdf/i1040sd.pdf

  6. Don says:

    Let’s hope DC legalizes grass soon.

  7. Todundsteuer says:

    Does this include the computation of taxable capital gains for the Alternative Minimum Tax (AMT) using the (AMT) Schedule D?

    How about taxable capital gains for computing the “Kiddie Tax” (Form 8615)?

    How about adjustments to US and Foreign source taxable capital gains for computing the foreign tax credit (Form 1116)?

    Are we having fun yet?

Leave a Reply to Brian Hayes Cancel reply

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


In addition to the basic HTML formatting options offered by the buttons above, you can also enter LaTeX math commands. Enclose LaTeX content in \( ... \) for inline mode or \[ ... \] for display mode.