Symbolic Lagrangian formulations of the equations of motion of tree-structured constrained mechanical systems have the potential to be both more efficient and more numerically robust than formulations which use nonlinear kinematic constraint equations. We derive a simple recursive factorization of the Lagrangian equations of motion which, along with our extended implementation of the D* symbolic differentiation algorithm, yields empirically measured O(n) inverse dynamics and O(n3) forward dynamics. Complex kinematic constraints such as point on surface, point on curve, and surface on surface are easily handled by the new algorithm. Numerous examples demonstrate the wide range of mechanical systems the algorithm can be applied to.