<story><title>Automatic Differentiation in 38 lines of Haskell</title><url>https://gist.github.com/ttesmer/948df432cf46ec6db8c1e83ab59b1b21</url></story><parent_chain></parent_chain><comment><author>sordina</author><text>One of my favourite Haskell &amp;quot;one-liners&amp;quot; is combining the AD package with Number.Symbolic:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    {-# LANGUAGE ImportQualifiedPost #-}
    
    module Module_1663406024_9206 where
    
    import Numeric.AD qualified as Ad
    import Data.Number.Symbolic qualified as Sym
    
    -- &amp;gt;&amp;gt;&amp;gt; f x = x^2 + 3 * x
    -- &amp;gt;&amp;gt;&amp;gt; Ad.diff f 1
    -- &amp;gt;&amp;gt;&amp;gt; Ad.diff f (Sym.var &amp;quot;a&amp;quot;)
    -- 5
    -- 3+a+a

    -- &amp;gt;&amp;gt;&amp;gt; Ad.diff sin pi
    -- &amp;gt;&amp;gt;&amp;gt; Ad.diff sin (Sym.var &amp;quot;a&amp;quot;)
    -- -1.0
    -- cos a
&lt;/code&gt;&lt;/pre&gt;
The package authors did not need to coordinate to make this possible which is pretty wild.&lt;p&gt;Saw it first here: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;twitter.com&amp;#x2F;GabriellaG439&amp;#x2F;status&amp;#x2F;647601518871359489&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;twitter.com&amp;#x2F;GabriellaG439&amp;#x2F;status&amp;#x2F;647601518871359489&lt;/a&gt;
and &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;www.reddit.com&amp;#x2F;r&amp;#x2F;haskell&amp;#x2F;comments&amp;#x2F;3r75hq&amp;#x2F;comment&amp;#x2F;cwmqphe&amp;#x2F;?utm_source=share&amp;amp;utm_medium=web2x&amp;amp;context=3&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;www.reddit.com&amp;#x2F;r&amp;#x2F;haskell&amp;#x2F;comments&amp;#x2F;3r75hq&amp;#x2F;comment&amp;#x2F;cwm...&lt;/a&gt;</text></comment>
<story><title>Automatic Differentiation in 38 lines of Haskell</title><url>https://gist.github.com/ttesmer/948df432cf46ec6db8c1e83ab59b1b21</url></story><parent_chain></parent_chain><comment><author>chrsig</author><text>one of the references is a talk by simon peyton jones on AD[0]&lt;p&gt;I&amp;#x27;m neither a math expert nor a haskell expert, but I happen to enjoy both.  It&amp;#x27;s been a while since I&amp;#x27;ve watched a SPJ lecture, and I&amp;#x27;d forgotten how much I want him to explain everything.&lt;p&gt;[0] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;www.youtube.com&amp;#x2F;watch?v=EPGqzkEZWyw&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;www.youtube.com&amp;#x2F;watch?v=EPGqzkEZWyw&lt;/a&gt;</text></comment>