Answers.Body: <p>That depends on the point-of-view. If you have some function given as a string of its mathematical formula and the output is the fully inserted string of its derivative, then the chain rule <span class="math-container">$(u\circ v)'(x)=u'(v(x))v'(x)$</span> quasi duplicates the occurrence of <span class="math-container">$v$</span>. This happens for each composition, so one can get an exponential growth in the string length from input to output.</p>
  <p>If you keep common sub-expressions separate, then what you do is parsing the function into a computational graph and taking the derivative of it. But this is already in the territory of algorithmic/automatic differentiation. If you do not keep the derivatives inside the original nodes, but split off additional nodes, then the output graph will double to triple in size relative to the original graph. This is a very compact representation of the symbolic derivative. Such structures have long been used and sometimes also exposed in CAS systems like Maple.</p>
  <p>The aim of AD is the <em>fast evaluation</em> of derivatives, so if evaluating in a point in a first sweep the node values and derivatives relative to the node input are computed, and each additional forward or backward sweep is just linear operations to compute tangents or gradients.</p>
  <hr />
  <p>In a ANN the network itself represents the computational graph, matrix-vector multiplication nodes/layers have the matrix and the input vector as the required node derivatives, for the scalar values of the activation function the node derivative needs to be computed separately. As the gradient computation has only one backward pass for each input, they can be computed just when they are needed.</p>
  <p>In short, backprop networks are already a part or an application of AD, there is not really a way to make this more efficient. In some cases (sparse graphs, multiple outputs,...) it can be useful to apply AD techniques to compress parts of the network, if the organizational overhead justifies the gains.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-22T13:56:21.570Z
Answers.LastActivityDate: 2022-12-11T16:32:27.557Z
Answers.LastEditDate: 2022-12-11T16:32:27.557Z
Answers.UserDisplayName: Lutz Lehmann
Body: <p>Today's computers can calculate symbolic derivatives quite fast, why is automatic differentiation still used? For example, Mathematica can handle algebraic operations with arrays. Doesn't automatic differentiation cause significant overhead? Calculating the symbolic gradient of an MLP should not be too difficult, or am I wrong?</p>
  
Tags: <multilayer-perceptrons><gradient>
Title: Why is automatic differentiation still used, if today's computers can calculate symbolic derivatives quite fast?
UserDisplayName: asd
ThreadText: # Why is automatic differentiation still used, if today's computers can calculate symbolic derivatives quite fast?
  
  (Asked by: username_0 on 2022-11-22)
  
  Today's computers can calculate symbolic derivatives quite fast, why is automatic differentiation still used? For example, Mathematica can handle algebraic operations with arrays. Doesn't automatic differentiation cause significant overhead? Calculating the symbolic gradient of an MLP should not be too difficult, or am I wrong?
  
  **Tags:** multilayer-perceptrons, gradient
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-11-22. Score: 4 | Accepted answer
  
  That depends on the point-of-view. If you have some function given as a string of its mathematical formula and the output is the fully inserted string of its derivative, then the chain rule $(u\circ v)'(x)=u'(v(x))v'(x)$ quasi duplicates the occurrence of $v$. This happens for each composition, so one can get an exponential growth in the string length from input to output.
  
  If you keep common sub-expressions separate, then what you do is parsing the function into a computational graph and taking the derivative of it. But this is already in the territory of algorithmic/automatic differentiation. If you do not keep the derivatives inside the original nodes, but split off additional nodes, then the output graph will double to triple in size relative to the original graph. This is a very compact representation of the symbolic derivative. Such structures have long been used and sometimes also exposed in CAS systems like Maple.
  
  The aim of AD is the *fast evaluation* of derivatives, so if evaluating in a point in a first sweep the node values and derivatives relative to the node input are computed, and each additional forward or backward sweep is just linear operations to compute tangents or gradients.
  
  ---
  
  In a ANN the network itself represents the computational graph, matrix-vector multiplication nodes/layers have the matrix and the input vector as the required node derivatives, for the scalar values of the activation function the node derivative needs to be computed separately. As the gradient computation has only one backward pass for each input, they can be computed just when they are needed.
  
  In short, backprop networks are already a part or an application of AD, there is not really a way to make this more efficient. In some cases (sparse graphs, multiple outputs,...) it can be useful to apply AD techniques to compress parts of the network, if the organizational overhead justifies the gains.
  
  
  ---
  
  