The Algebra of Directed Acyclic Graphs