Russ Cox presents an alternative proof of correctness for Donald Knuth's P2 algorithm, which converts 16-bit fixed-point binary fractions to shortest accurate decimal representations. Starting with a trivially correct program in Ivy (an APL-like calculator language), Cox incrementally transforms it into Knuth's P2 through a

27m read timeFrom research.swtch.com
Post cover image
Table of contents
IntroductionProblem StatementNotationInitial SolutionInitial Proof of CorrectnessTestingWalking DigitsPremultiplicationCollecting DigitsChange of BasisDiscard Integer PartsRefactoringScalingSimpler Programs and ProofsA More Direct SolutionA Textbook SolutionConclusion

Sort: