<divclass="platform-hinted "data-platform-hinted="data-platform-hinted"><divclass="content sourceset-dependent-content"data-active=""data-togglable=":kmath-core:dokkaHtmlPartial/commonMain"><divclass="symbol monospace"><spanclass="token keyword"></span><spanclass="token keyword">fun </span><spanclass="token operator"><</span><spanclass="token keyword"></span><ahref="derive.html">R</a><spanclass="token operator">></span><ahref="derive.html"><spanclass="token function">derive</span></a><spanclass="token punctuation">(</span><spanclass="parameters "><spanclass="parameter ">value<spanclass="token operator">: </span><ahref="derive.html">R</a><spanclass="token punctuation">, </span></span><spanclass="parameter ">block<spanclass="token operator">: </span><spanclass="token keyword"></span><ahref="index.html">F</a><spanclass="token punctuation">.</span><spanclass="token punctuation">(</span><spanclass="token keyword"></span><ahref="derive.html">R</a><spanclass="token punctuation">)</span><spanclass="token operator"> -></span><spanclass="token keyword"></span><ahref="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></span></span><spanclass="token punctuation">)</span><spanclass="token operator">: </span><ahref="derive.html">R</a><spanclass="clearfix"><spanclass="floating-right">(<ahref="https://github.com/SciProgCentre/kmath/tree/master/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt#L134">source</a>)</span></span></div><pclass="paragraph">Performs update of derivative after the rest of the formula in the back-pass.</p><pclass="paragraph">For example, implementation of <codeclass="lang-kotlin">sin</code> function is:</p><divclass="sample-container"><pre><codeclass="block lang-kotlin"theme="idea">fun AD.sin(x: Variable): Variable = derive(Variable(sin(x.x)) { z -> // call derive with function result<br> x.d += z.d * cos(x.x) // update derivative using chain rule and derivative of the function<br>}</code></pre><spanclass="top-right-position"><spanclass="copy-icon"></span><divclass="copy-popup-wrapper popup-to-left"><spanclass="copy-popup-icon"></span><span>Content copied to clipboard</span></div></span></div></div></div>