Challenge: Automatic differentiation in D

Robert Fraser fraserofthenight at gmail.com
Tue May 12 18:39:30 PDT 2009


Bill Baxter wrote:
> If I had the time I'd love to play around with automatic differentiation in D.
> http://en.wikipedia.org/wiki/Automatic_differentiation
> 
> I played around with it a bit in C++ before, using the operator
> overloading approach, but didn't go much beyond basic polynomials with
> it.
> The page above offers something of a challenge for a potential D implementation:
> """
> Operator overloading for forward accumulation is easy to implement,
> and also possible for reverse accumulation. However, current compilers
> lag behind in optimizing the code when compared to forward
> accumulation.
> """
> 
> I wonder if the fancy compile-time machinery offered by D could enable
> a more efficient implementation?
> 
> Ultimately I'd be interested in using AD for implementing physics-y
> things where complicated derivatives end up being necessary all the
> time.
> Here's a paper where they made use of a simple AD implementation for
> doing thin shell simulations:
> http://www.cs.columbia.edu/cg/pdfs/10_ds.pdf
> You can also find their C++ AD code on the caltech site somewhere.
> 
> Just throwing this out there, because occasionally there are folks
> looking for little self-contained projects to undertake.  And because
> I think AD is nifty.
> 
> --bb

I can't forsee any compiler issues if you use an interface like:

mixin(ctfeFunc("expression"));

That said, you'd need to do all the parsing, etc. in CTFE if you went 
that route. Without macros, though, the only other way would be abuse of 
operator overloading, which might prove to be more difficult anyway.



More information about the Digitalmars-d mailing list