Dear Hipparchus community,
I am fond of high-order, multivariate automatic differentiation and first of all, I would like to thank the developers for providing an open-source implementation of it in Java via the DerivativeStructure class, even though the lack of operator overload in this language makes its use more tedious. Actually, the real achievement was to systematically code methods in Orekit both with doubles and DerivativeStructures, so kudos on that as well.
Before seeing it in the Javadoc, I wasn’t aware of Dan Kalman’s paper. So I’ve read it and… my conclusion is that Hipparchus’ DerivativeStructure class is far from being a textbook implementation of it. To be honest, it’s just borrowing a few ideas. Indeed, the author basically proposes to perform ALL operations recursively, meaning that DerivativeStructure objects should hold as attributes other instances with less variables or derivatives, until things unfold down to real numbers. Even for the « add » operator. But in Hipparchus, it is implemented as a straight-forward pair-wise additions of corresponding terms, there is no recursion on substructures as the partial derivatives are handled directly. Don’t get me wrong, I’m not saying this is a bad thing: as Dan Kalman admits himself, his concept is elegant as very little code is needed, but it is certainly not the most efficient as far as computational cost is concerned. I’m just saying that maybe Hipparchus’ documentation shouldn’t claim that it implements his ideas, but only that it is merely inspired from it. In my opinion, the present DerivativeStructure class is far closer to Berz’s seminal work in the 80s-90s (please share your thoughts if you disagree), see for example:
BERZ, A. Differential algebraic description of beam dynamics to very high orders. Part. Accel., 1988, vol. 24, no SSC-152, p. 109-124.
Now, to my second point. It is my understanding that the « compose » function in DSCompiler only allows to combine derivatives up to order N from a univariate function with the derivatives of an arbitrary multivariate function up to order N. Is that correct ? If so, I must say that it is not very clear from the Javadoc and I would suggest reformulating. By the way, the use of that method in Hipparchus for the intrinsic functions (e.g. exp) is again far from what Dan Kalman proposes on the subject in his paper (and which might be his best contribution)!
Anyhow, the fact is that sets of partial derivatives can be combined as long as they have the same maximum order and that the number of variables of the left hand side equals the number of functions on the right hand side. What I’m saying is that for example f(g,h) makes sense as long as f is bivariate and g and h map the same number of variables to R. But I don’t see in Hipparchus how to do that with DerivativeStructures. As a matter of fact, this is a necessary feature to perform Taylor map inversion (as requested in Issue #190). It implies manipulating different DSCompiler at the same time. It is not trivial yet not too tricky I believe and it would be very appreciable to have that in Hipparchus!
Cheers,
Romain.