TITLE: How to debug math?
QUESTION [61 upvotes]: May seem strange as I'm good in programming, but I just started diving into math. ATM I'm learning combinatorics at Khan Academy, and here's an example of a question that I struggled with (that's not the question):

The answer to «ways of getting $1$ head in $4$ flips» is $4$ (HTTT, THTT, TTHT, TTTH). But let's put it the other way round: «ways of getting $3$ tails in $4$ flips» (which is, obviously, the same question). It would be the number of places to put it: $4×3×2 = 24$, next divided by 3 to remove duplicates (i.e. TTTH is counted $3$ times): $24/3 = 8$. But $8 ≠ 4$! We used right calculations, reasoning, and got absolutely different answer, how is that possible?

I thought: there must be generic ways of debugging math problems, i.e. not just directly solving, but rather finding the problem when everything supposed to work, but it doesn't. I tried searching, and to my surprise found nothing, like nobody ever asked the question. Well, here's mine:
What are common ways to debug math problems; both generic and specialized would be nice to know. If you know any relevant articles, I'd be glad to read it too.

REPLY [11 votes]: Regarding math at the graduate level and beyond, these programming debugging techniques can be quite effective:

Rubber duck debugging:  Find someone/something to whom to explain the bug and your solution.  This is also effective for helping undergraduates find bugs in their solutions to word problems.  Code review, i.e., presenting your argument to an at least minimally interested colleague, finds many, many bugs by the same mechanism.
Bisection: Did the claim hold half-way through a construction?  Either way, next check at the appropriate quarter point.
Unit Testing:  In math, this comprises having a pool of "friendly" and a pool of "bizarre" objects to test claims on.  Examples:  Does this claim hold for $[0,1]$?  How about for the Cantor set?  How about for the uncountable product of copies of $[0,1]$?  Does it work for Abelian groups?  solvable groups?  finitely generated groups?  Lie groups? et al.
Precondition checking:  This theorem holds if that measure is $\sigma$-finite.  Is that measure $\sigma$-finite?  (This catches many, many bugs.  Notorious example involving a definition: manifolds are Hausdorff, but there are published papers that forget to check this.)  In fact, all theorems are (software "design by contract") contracts.