<div dir="ltr">Hello Café<div><br></div><div><b>Issue: </b></div><div>I'm having trouble using the AD package presumably due to a wrong use of types (Sorry I know it's a bit vague)</div><div>Any help or pointer on how to solve this would be greatly appreciated.</div><div>Thanks in advance</div><div><br></div><div><b>Background: </b></div><div>I've implemented a symbolic expression tree [full code here: <a href="https://pastebin.com/FDpSFuRM">https://pastebin.com/FDpSFuRM</a>]</div><div><div><font face="monospace" color="#666666">-- | Expression Tree</font></div><div><font face="monospace" color="#666666">data ExprTree a = Const a -- ^ number</font></div><div><font face="monospace" color="#666666"> | ParamNode ParamName -- ^ parameter</font></div><div><font face="monospace" color="#666666"> | VarNode VarName -- ^ variable</font></div><div><font face="monospace" color="#666666"> | UnaryNode MonoOp (ExprTree a) -- ^ operator of arity 1</font></div><div><font face="monospace" color="#666666"> | BinaryNode DualOp (ExprTree a) (ExprTree a) -- ^ operator of arity 2</font></div><div><font face="monospace" color="#666666"> | CondNode (Cond a) (ExprTree a) (ExprTree a) -- ^ conditional node</font></div><div><font face="monospace" color="#666666"> deriving (Eq,Show, Generic)</font></div></div><div><br></div><div>An evaluation function on it</div><div><div><font face="monospace">-- | evaluates an Expression Tree on its Context (Map ParamName a, Map VarName a)</font></div><div><font color="#666666"><font face="monospace">evaluate :: (Eq a, Ord a, Floating a) </font><span style="font-family:monospace">=> ExprTree a </span><span style="font-family:monospace">-> Context a </span><span style="font-family:monospace">-> a</span></font></div></div><div><br></div><div>And a few instances on it:</div><div><div><font face="monospace" color="#666666">instance Num a => Default (ExprTree a) where ...</font></div></div><div><div><font face="monospace" color="#666666">instance Num a => Num (ExprTree a) where ...</font></div></div><div><div><font face="monospace" color="#666666">instance Fractional a => Fractional (ExprTree a) where ...</font></div></div><div><div><font face="monospace" color="#666666">instance Floating a => Floating (ExprTree a) where ...</font></div></div><div><div><font face="monospace" color="#666666">instance (Arbitrary a) => Arbitrary (ExprTree a) where ...</font></div></div><div><br></div><div>This allows me to easily create (using derivation rules) the derivative(s) of such a tree with respect to its variable(s):</div><div><div><font face="monospace" style="color:rgb(102,102,102)">diff :: (Eq a, Floating a) </font><span style="color:rgb(102,102,102);font-family:monospace">=> ExprTree a </span><span style="color:rgb(102,102,102);font-family:monospace">-> VarName </span><span style="color:rgb(102,102,102);font-family:monospace">-> ExprTree a</span><br></div></div><div><div><font color="#666666"><font face="monospace">grad :: (Eq a, Floating a) </font><span style="font-family:monospace">=> ExprTree a </span><span style="font-family:monospace">-> Map VarName (ExprTree a)</span></font></div></div><div><div><font color="#666666"><font face="monospace">hessian :: (Eq a, Floating a) </font><span style="font-family:monospace">=> ExprTree a </span><span style="font-family:monospace">-> Map VarName (Map VarName (ExprTree a))</span></font></div></div><div><br></div><div>So far, so good ...</div><div><br></div><div>Now, to gain assurance in my implementation I wanted to check the derivatives against the Numeric.AD module</div><div>so I create the two following</div><div><font face="monospace" color="#666666">-- | helper for AD usage</font></div><div><font face="monospace" color="#666666">exprTreeToListFun :: (RealFloat a)</font></div><div><font face="monospace" color="#666666"> => ExprTree a -- ^ tree</font></div><div><font face="monospace" color="#666666"> -> Map ParamName a -- ^ paramDict</font></div><div><font face="monospace" color="#666666"> -> ([a] -> a) -- fun from var values to their evaluation</font></div><div><font face="monospace" color="#666666">exprTreeToListFun tree paramDict vals = res</font></div><div><font face="monospace" color="#666666"> where</font></div><div><font face="monospace" color="#666666"> res = evaluate tree (paramDict, varDict)</font></div><div><font face="monospace" color="#666666"> varDict = Map.fromList $ zip (getVarNames tree) vals</font></div><div><font face="monospace" color="#666666"><br></font></div><div><font face="monospace" color="#666666"><br></font></div><div><font face="monospace" color="#666666">gradThroughAD :: RealFloat a => ExprTree a -> Context a -> Map VarName a</font></div><div><font face="monospace" color="#666666">gradThroughAD tree (paramDict, varDict) = res</font></div><div><font face="monospace" color="#666666"> where</font></div><div><font face="monospace" color="#666666"> varNames = Map.keys varDict</font></div><div><font face="monospace" color="#666666"> varVals = Map.elems varDict</font></div><div><font face="monospace" color="#666666"> gradList = AD.grad (exprTreeToListFun tree paramDict) varVals</font></div><div><font face="monospace" color="#666666"> res = Map.fromList $ zip varNames gradList</font></div><div><font face="monospace" color="#666666"><br></font></div><div><font face="monospace" color="#666666"><br></font></div><div>it unfortunately does not type check with message:</div><span style="box-sizing:border-box;padding:0.5em 0px;margin:0px;color:rgb(170,170,170);font-family:blinkmacsystemfont,"lucida grande","segoe ui",ubuntu,cantarell,sans-serif;font-size:11px;line-height:15.7143px;background-color:rgb(29,31,33)"><span style="box-sizing:border-box;display:block;padding:0.2em 1em;color:rgb(208,208,208);font-family:consolas,monospace;white-space:pre-wrap;border-radius:0.5em"><span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">• Couldn't match type </span><span style="box-sizing:border-box">‘</span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box">’</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> with </span><span style="box-sizing:border-box">‘</span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span class="inbox-inbox-syntax--support inbox-inbox-syntax--other inbox-inbox-syntax--module inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">Numeric.AD.Internal.Reverse.</span></span><span style="box-sizing:border-box">Reverse</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">s</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box">’</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span style="box-sizing:border-box">‘</span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box">’</span><span style="box-sizing:border-box"> is a rigid type variable bound by</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> the type signature for:</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span class="inbox-inbox-syntax--meta inbox-inbox-syntax--function inbox-inbox-syntax--type-declaration inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--function inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(97,175,239)"><span style="box-sizing:border-box">gradThroughAD</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--other inbox-inbox-syntax--double-colon inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(198,120,221)"><span style="box-sizing:border-box">::</span></span><span class="inbox-inbox-syntax--meta inbox-inbox-syntax--type-signature inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--other inbox-inbox-syntax--forall inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(198,120,221)"><span style="box-sizing:border-box">forall</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--variable inbox-inbox-syntax--other inbox-inbox-syntax--generic-type inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">a</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">.</span></span></span></span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span class="inbox-inbox-syntax--meta inbox-inbox-syntax--function inbox-inbox-syntax--type-declaration inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span class="inbox-inbox-syntax--meta inbox-inbox-syntax--type-signature inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--type inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(229,192,123)"><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--other inbox-inbox-syntax--inherited-class inbox-inbox-syntax--prelude inbox-inbox-syntax--RealFloat inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(152,195,121)"><span style="box-sizing:border-box">RealFloat</span></span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--variable inbox-inbox-syntax--other inbox-inbox-syntax--generic-type inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--other inbox-inbox-syntax--big-arrow inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(198,120,221)"><span style="box-sizing:border-box">=></span></span></span></span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span class="inbox-inbox-syntax--meta inbox-inbox-syntax--function inbox-inbox-syntax--type-declaration inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span class="inbox-inbox-syntax--meta inbox-inbox-syntax--type-signature inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--type inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(229,192,123)"><span style="box-sizing:border-box">ExprTree</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--variable inbox-inbox-syntax--other inbox-inbox-syntax--generic-type inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--other inbox-inbox-syntax--arrow inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(198,120,221)"><span style="box-sizing:border-box">-></span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--type inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(229,192,123)"><span style="box-sizing:border-box">Context</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--variable inbox-inbox-syntax--other inbox-inbox-syntax--generic-type inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--other inbox-inbox-syntax--arrow inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(198,120,221)"><span style="box-sizing:border-box">-></span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--type inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(229,192,123)"><span style="box-sizing:border-box">Map</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--type inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(229,192,123)"><span style="box-sizing:border-box">VarName</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--variable inbox-inbox-syntax--other inbox-inbox-syntax--generic-type inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">a</span></span></span></span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">at</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">src</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">/</span></span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span class="inbox-inbox-syntax--support inbox-inbox-syntax--other inbox-inbox-syntax--module inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">SymbolicExpression.</span></span><span style="box-sizing:border-box">hs</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">452</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">18</span></span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">Expected</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--other inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(198,120,221)"><span style="box-sizing:border-box">type</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span style="box-sizing:border-box"> [</span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span class="inbox-inbox-syntax--support inbox-inbox-syntax--other inbox-inbox-syntax--module inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">Numeric.AD.Internal.Reverse.</span></span><span style="box-sizing:border-box">Reverse</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">s</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box">]</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">-></span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span class="inbox-inbox-syntax--support inbox-inbox-syntax--other inbox-inbox-syntax--module inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">Numeric.AD.Internal.Reverse.</span></span><span style="box-sizing:border-box">Reverse</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">s</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">Actual</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--other inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(198,120,221)"><span style="box-sizing:border-box">type</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span style="box-sizing:border-box"> [</span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box">] </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">-></span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">• In the first argument of </span><span style="box-sizing:border-box">‘</span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span class="inbox-inbox-syntax--support inbox-inbox-syntax--other inbox-inbox-syntax--module inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">AD.</span></span><span style="box-sizing:border-box">grad</span></span><span style="box-sizing:border-box">’</span><span style="box-sizing:border-box">, namely</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span style="box-sizing:border-box">‘</span><span style="box-sizing:border-box">(</span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">exprTreeToListFun</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">tree</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">paramDict</span></span><span style="box-sizing:border-box">)</span><span style="box-sizing:border-box">’</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> In the expression:</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span class="inbox-inbox-syntax--support inbox-inbox-syntax--other inbox-inbox-syntax--module inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">AD.</span></span><span style="box-sizing:border-box">grad</span></span><span style="box-sizing:border-box"> (</span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">exprTreeToListFun</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">tree</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">paramDict</span></span><span style="box-sizing:border-box">) </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">varVals</span></span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">In</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">an</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">equation</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">for</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">‘</span></span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">gradList</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">’:</span></span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">gradList</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">=</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span class="inbox-inbox-syntax--support inbox-inbox-syntax--other inbox-inbox-syntax--module inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">AD.</span></span><span style="box-sizing:border-box">grad</span></span><span style="box-sizing:border-box"> (</span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">exprTreeToListFun</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">tree</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">paramDict</span></span><span style="box-sizing:border-box">) </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">varVals</span></span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">• Relevant bindings include</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> gradList :</span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span style="box-sizing:border-box"> [</span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box">] (</span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">bound</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">at</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">src</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">/</span></span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span class="inbox-inbox-syntax--support inbox-inbox-syntax--other inbox-inbox-syntax--module inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">SymbolicExpression.</span></span><span style="box-sizing:border-box">hs</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">457</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">5</span></span><span style="box-sizing:border-box">)</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> varVals :</span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span style="box-sizing:border-box"> [</span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box">] (</span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">bound</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">at</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">src</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">/</span></span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span class="inbox-inbox-syntax--support inbox-inbox-syntax--other inbox-inbox-syntax--module inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">SymbolicExpression.</span></span><span style="box-sizing:border-box">hs</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">456</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">5</span></span><span style="box-sizing:border-box">)</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> varDict :</span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">Map</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">VarName</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> (bound at src/SymbolicExpression.hs:</span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">453</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">32</span></span><span style="box-sizing:border-box">)</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> paramDict :</span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">Map</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">ParamName</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> (bound at src/SymbolicExpression.hs:</span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">453</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">21</span></span><span style="box-sizing:border-box">)</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> tree :</span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">ExprTree</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box"> (</span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">bound</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">at</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">src</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">/</span></span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span class="inbox-inbox-syntax--support inbox-inbox-syntax--other inbox-inbox-syntax--module inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">SymbolicExpression.</span></span><span style="box-sizing:border-box">hs</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">453</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">15</span></span><span style="box-sizing:border-box">)</span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> gradThroughAD :</span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">ExprTree</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">-></span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">Context</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">-></span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">Map</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--entity inbox-inbox-syntax--name inbox-inbox-syntax--tag inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(224,108,117)"><span style="box-sizing:border-box">VarName</span></span><span style="box-sizing:border-box"> </span><span class="inbox-inbox-syntax--identifier inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box">a</span></span></span>
<span class="inbox-inbox-syntax--hint inbox-inbox-syntax--message inbox-inbox-syntax--haskell" style="box-sizing:border-box"><span style="box-sizing:border-box"> (bound at src/SymbolicExpression.hs:</span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">453</span></span><span class="inbox-inbox-syntax--keyword inbox-inbox-syntax--operator inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(171,178,191)"><span style="box-sizing:border-box">:</span></span><span class="inbox-inbox-syntax--constant inbox-inbox-syntax--numeric inbox-inbox-syntax--decimal inbox-inbox-syntax--haskell" style="box-sizing:border-box;color:rgb(209,154,102)"><span style="box-sizing:border-box">1</span></span><span style="box-sizing:border-box">)</span></span>
</span></span><span style="box-sizing:border-box;padding:0.5em 0px;margin:0px;color:rgb(170,170,170);font-family:blinkmacsystemfont,"lucida grande","segoe ui",ubuntu,cantarell,sans-serif;font-size:11px;line-height:15.7143px;background-color:rgb(29,31,33)"><div><span style="box-sizing:border-box;padding:0.5em 0px;margin:0px;color:rgb(170,170,170);font-family:blinkmacsystemfont,"lucida grande","segoe ui",ubuntu,cantarell,sans-serif;font-size:11px;line-height:15.7143px;background-color:rgb(29,31,33)"><br></span></div><br class="inbox-inbox-Apple-interchange-newline"></span><div>I was a bit surprised (I guess naively) by this, since to me, 'a' is polymorphic with RealFloat as type constraint and that is "supposed" to work with AD</div><div> </div><div>So anyway, I tried to modify as follow:</div><div><font color="#666666" face="monospace">{-# LANGUAGE Rank2Types #-}</font></div><div><font color="#666666" face="monospace"><br></font></div><div><font color="#666666" face="monospace">-- | helper for AD usage</font></div><div><font color="#666666" face="monospace">exprTreeToListFun :: (RealFloat a)</font></div><div><font color="#666666" face="monospace"> => ExprTree a -- ^ tree</font></div><div><font color="#666666" face="monospace"> -> Map ParamName a -- ^ paramDict</font></div><div><font face="monospace"><font color="#666666"> -> </font><b><font color="#0000ff">(RealFloat b => </font></b><font color="#666666">[b] -> b) -- fun from var values to their evaluation</font></font></div><div><font color="#666666" face="monospace">exprTreeToListFun tree paramDict vals = res</font></div><div><font color="#666666" face="monospace"> where</font></div><div><font color="#666666" face="monospace"> res = </font><font face="monospace" color="#0000ff"><b>realToFrac</b></font><font color="#666666" face="monospace"> $ evaluate tree (paramDict, varDict)</font></div><div><font face="monospace"><font color="#666666"> varDict = Map.fromList $ zip (getVarNames tree) </font><b><font color="#0000ff">$ map realToFrac </font></b><font color="#666666">vals</font></font></div><div> </div><div>This now typechecks and runs but going through AD returns me <u>all derivatives as zero</u> as if treating the variables (that passed through <b style="font-family:monospace"><font color="#0000ff">realToFrac</font></b>) as constants, so not that much helpful either.</div><div><br></div><div>Any idea how this can be solved ?</div><div><br></div><div>Apologies if this is a question that already has an answer somewhere but <a href="http://stackoverflow.com/search?q=%5Bhaskell%5D+ad+package ">poking around SO</a> It looks like I'm not the only one having similar issues and unfortunately none of the answers I found really helped me, if anything it confirms the same issue of null derivatives: <a href="http://stackoverflow.com/questions/36878083/ad-type-unification-error-with-constrained-type-vector">http://stackoverflow.com/questions/36878083/ad-type-unification-error-with-constrained-type-vector</a></div><div><br></div><div>Thanks again</div><div><br></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><div><font color="#000000">Frederic Cogny<br></font></div><font color="#000000"><font>+33 </font><span>7 83 12 61 69</span></font><br></div></div>