Creating a library for symbolic algebra in Nim is pretty cool, but you don't 
need to follow the design of Python where the expression tree is constructed at 
run-time through operator overloading. In Nim, you can directly work with the 
AST-form of arbitrary formulas at compile-time by creating a macro that will 
take a block of code. You can also use the macros.getImpl family of magics to 
obtain the code of existing functions and transform it in arbitrary ways.

This approach will give you more power - not only you will be able to 
differentiate functions, but you'll be also able to turn the computed 
derivative into generated code that will be compiled with full optimisations by 
the C/C++ compiler.

Gradient descent with back-propagation can be applied to many fields and it can 
greatly benefit from a capability like this. ArrayMancer is a famous library 
that already provides something similar: 
[https://github.com/mratsim/Arraymancer/tree/master/src/autograd](https://github.com/mratsim/Arraymancer/tree/master/src/autograd)

Reply via email to