The Mathematics of Genealogy