Beware of bugs in the above code; I have only proved it correct, not tried it.
Donald Knuth on the difference between theory and practice.
Duplicate.
Donald Knuth on the difference between theory and practice.
Duplicate.