Wednesday, July 9, 2008

Countable Rational Numbers

In my Real Analysis class in college I remember seeing the proof that rational numbers are countable via a diagonalisation argument. Proving something is true and implementing a counting algorithm that will assign any given Rational a unique positive integer are two very different things.

This link is class room explanation behind all the math without dumbing anything down. Here's the original amazing paper by virtue of simplicity and elegance. The only things needed to understand it is the most rudimentary understanding of binary trees and Euclid’s gcd algorithm.

I wrote up some scheme code to print out the "parents" of the node, which allows one to assign a unique positive integer to every/any Rational.


;Tree
(define (display-all . args) (display args))
(define (p-parents m n)
(cond ((or (zero? m) (zero? n)))
((= m n) (display-all 1 "\n") 1)
((< m n) (display-all m " " n "\n")(p-parents m (- n m)))
((> m n) (display-all m " " n "\n")(p-parents (- m n) n))))

;Print the parent nodes of 49/19
(p-parents 49 19)

No comments: