The first alternative builds a large tree structure, and then evaluates the whole tree structure afterwards.<p>So first it blows up the size of the expression to process and <i>then</i> it calculates the result. A lot of those calculations will be redundant<p>The second one not only avoids evaluating the tree separately, but &quot;prunes&quot; a lot of the evaluation automatically by effectively short-circuiting the whole process. Consider (with the caveat that my Haskell understanding is rudimentary at best and it was about 20 years since I last did anything involving symbolic differentiation) :<p><pre><code>   Product e e&#x27; -&gt; Product e (diff e&#x27;) `Sum` Product (diff e) e&#x27;
</code></pre>
Followed by a separate run with:<p><pre><code>    Product e e&#x27; -&gt; ev e * ev e&#x27;
</code></pre>
vs<p><pre><code>    Product e e&#x27; -&gt; let (ex, ed)   = ev e
                            (ex&#x27;, ed&#x27;)       = ev e&#x27;
                    in (ex * ex&#x27;, ex * ed&#x27; + ed * ex&#x27;)
</code></pre>
(I pick the &quot;Product&quot; rule as an example because it is one of the ones that blows up the size of the tree)<p>Lets say you do something simple like Product X X. You get Sum (Product X One) (Product One X) out, and then you have to evaluate each node.<p>In the second case, you match Product e e&#x27;. You process X and assign (x,1) to (ex,ed), and process the second X and assign (x,1) to (ex&#x27;, ed&#x27;), and then return (ex * ex&#x27;, ex * ed&#x27; + ed * ex&#x27;).<p>In the first case, you&#x27;ve first differentiated 3 nodes (Product + 2x &quot;X&quot;), then evaluated the 7 nodes that was produced as output, for a total of ten nodes processed.<p>In the second you&#x27;ve evaluated&#x2F;differentatiated 3 nodes in one go without the intermediate step of having to evaluate a much larger tree.<p>In a large example, the number of nodes in the differentiated output quickly explodes and subsequent evaluation would increase rapidly in cost.