Add automatic differentiation
This has been requested several times.
The first step would be to add code that takes an ASR of some Fortran function and returns the derivative as an ASR.
Then one can easily write a Python script that will retrieve a Fortran function from a module, differentiates and generates Fortran code in a new module.
Further improvement can be to have something like pragmas, something like:
!pragma lfortran autodiff(pow_diff) real(dp) function pow(x, a) pow = x**a end function
which would call an
autodifffunction implemented in step 1. above, and "insert" the generated function in the current module as
pod_difffunction. This would be a general mechanism how to create "macros" or anything else we want. One would simply implement any such custom functionality, say, using the Python API of LFortran.
Another option to explore would be to add a new type, for example as an LFortran extension implemented using the code from 1. I don't know if that makes sense or not, I feel the option 3. might be the best way to integrate this with Fortran.
We can get inspired, e.g., by the Zygote module in Julia.