A mathematical theory of the topological vertex