reduce -> forloop in treeapply doctest