ComputerAlgebra icon indicating copy to clipboard operation
ComputerAlgebra copied to clipboard

Ln1Exp and other numerical optimizations

Open Federerer opened this issue 3 years ago • 0 comments

Hi, I remember that one time we had a conversation about how to handle numerical optimizations e.g. for ln(1 + exp(x)) stuff. So, I tested it. Implementation is rather simplistic, and I've just added some code to the CompileExpression visitor, but it should be probably done in some more organized way (e.g. separate visitor per optimization). I was wondering if it's possible to use SubstituteTransform for that? But this is more like a run-time optimization, and it fits better for the compilation step. I've also tried adding Ln1Exp function to the global namespace directly, so it can be used in models, but it causes many problems (e.g. with differentiation). BTW, that's why I had to add a linear extension to the exp function, because without Call.If in triode models, Computer Algebra produces different results, containing exp function calls in derivatives, which wasn't the case in old version because of how derivatives are handled for function containing if expression 😉

new SubstituteTransform("D[If[c, t, f], x]", "If[c, D[t, x], D[f, x]]")

Anyway, I hope that you can point me in the right direction with this 😄

Federerer avatar Apr 04 '22 10:04 Federerer