Efficient Compilation of a Class of Variational Forms